lar*_*sks 7 configuration-management puppet augeas
我在使用以下 Puppet 清单时遇到问题,该清单旨在启用passwdqcRHEL-6 系统上的pam 模块(使用 Puppet 0.25.5 和 augeas 0.7.2):
augeas { 'authconfig':
context => '/files/etc/sysconfig/authconfig',
changes => [
'set USEPASSWDQC yes',
'set USECRACKLIB no',
],
notify => Exec['authconfig-all'],
}
exec { 'authconfig-all':
command => '/usr/sbin/authconfig --updateall',
refreshonly => true,
}
Run Code Online (Sandbox Code Playgroud)
如果我运行此清单,它似乎成功完成:
info: Applying configuration version '1311189237'
notice: //Augeas[authconfig]/returns: executed successfully
info: //Augeas[authconfig]: Scheduling refresh of Exec[authconfig-all]
notice: //Exec[authconfig-all]: Triggering 'refresh' from 1 dependencies
Run Code Online (Sandbox Code Playgroud)
但如果我检查目标文件,更改尚未应用:
# egrep 'PASSWDQC|CRACKLIB' /etc/sysconfig/authconfig
USECRACKLIB=yes
USEPASSWDQC=no
Run Code Online (Sandbox Code Playgroud)
如果我notify => ...从清单中删除该行,它会完全按预期工作。也就是说,鉴于此:
augeas { 'authconfig':
context => '/files/etc/sysconfig/authconfig',
changes => [
'set USEPASSWDQC yes',
'set USECRACKLIB no',
],
}
Run Code Online (Sandbox Code Playgroud)
更改已成功保存:
# puppet /path/to/manifest.pp
info: Applying configuration version '1311189502'
notice: //Augeas[authconfig]/returns: executed successfully
# egrep 'PASSWDQC|CRACKLIB' /etc/sysconfig/authconfig
USECRACKLIB=no
USEPASSWDQC=yes
Run Code Online (Sandbox Code Playgroud)
知道这里发生了什么吗?显然,puppet认为更改是第一次进行,但实际上并没有保存到磁盘。我们还有其他使用 augeas 和通知操作的配置,它们工作得很好;我们一直无法弄清楚为什么这会失败。请注意,如果我将notifyaugeas 操作替换subscribe为相应的exec定义,则存在相同的问题。
我目前的计划是用最新版本的 puppet 和 augeas 构建软件包,看看问题是否会神奇地消失。
更新:freiheit 指出authconfig似乎正在覆盖此文件。奇怪的是,在 CentOS 5 下,修改/etc/sysconfig/authconfig然后运行authconfig --updateall是完全正确的过程。这就是我们在旧版 Kickstart 中实际使用的内容。
很明显,RHEL6 升级已经authconfig以奇怪和无用的方式表现出来。
部分答案是authconfig命令的行为在 RHEL5 和 RHEL6 之间发生了变化。在 RHEL6 中,不是读取 /etc/sysconfig/authconfig然后生成配置,而是authconfig在 RHEL6 中解析它管理的每个单独的配置文件,然后生成 /etc/sysconfig/authconfig作为当前状态的记录。
这意味着,如果 (a) 试图避免运行authconfig命令,或 (b) 试图利用authconfig命令行不支持的功能,则必须直接编辑配置文件。
这就是我最终启用passwdqcPAM 模块的结果:
augeas { 'pam_passwdqc':
context => '/files/etc/pam.d/system-auth-ac/',
changes => [
'rm *[module="pam_cracklib.so"]',
'ins 9999 before *[type="password"][module="pam_unix.so"]',
'set 9999/type password',
'set 9999/control requisite',
'set 9999/module pam_passwdqc.so',
'set 9999/argument enforce=everyone',
],
onlyif => 'match *[module="pam_passwdqc.so"] size == 0',
notify => Exec['authconfig-update-all'],
}
exec { 'authconfig-update-all':
command => '/usr/sbin/authconfig --updateall',
refreshonly => true,
}
Run Code Online (Sandbox Code Playgroud)
如果您发现自己正在阅读这个答案,我很想听听您对这是否是处理事情的理智方式的评论。我是 Puppet 的新手,所以我仍然对事情的运作方式有所了解。