我在使用以下 Puppet 清单时遇到问题,该清单旨在启用passwdqc
RHEL-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 { …
Run Code Online (Sandbox Code Playgroud) 假设我在/etc/syslog.conf
文件中有以下内容:
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
Run Code Online (Sandbox Code Playgroud)
我想将其更改kern.* /var/log/kern.log
为获取内核日志的人类可读时间戳。
木偶可以做到:
class syslog::config {
file { "/etc/syslog.conf":
ensure => present,
source => "puppet:///modules/syslog/syslog.conf",
require => Class["syslog::install"],
notify => Class["syslog::service"],
}
}
Run Code Online (Sandbox Code Playgroud)
或者我也可以使用sed -i
.
使用Augeas,我可以将此行附加到文件末尾:
class syslog::config {
augeas { "syslogkern":
context => "/files/etc/syslog.conf",
changes => [
"set entry[last()+1]/selector/facility kern",
"set entry[last()]/selector/level *",
"set entry[last()]/action/file '/var/log/kern.log'",
],
}
}
Run Code Online (Sandbox Code Playgroud)
或修改目的地:
class syslog::config …
Run Code Online (Sandbox Code Playgroud) 我正在开发用于管理 JBoss 应用服务器的自定义 puppet 模块。我认为应用服务器上部署的每个应用程序都是一个自包含的资源。但是一些应用程序需要在 JBoss 的配置文件中进行专门的配置更改。
每个应用程序也是一个傀儡资源,但大多数应用程序彼此不认识。
目前我使用 augeas 对 JBoss 的配置文件进行更改。即使许多资源需要更改该配置文件,它也能工作,但它非常复杂、容易出错且速度缓慢。
实际上,我想对配置文件使用模板,但问题是如何在触发模板机制之前聚合来自不同(子)模块的所有必需工件,而不必知道 man 配置工件有多少?
例子:
define jboss_config($config) {
# do something with the config
}
jboss_config {
config => 'some configuration for app 1'
}
jboss_config {
config => 'some configuration for app 2'
}
jboss_config {
config => 'some configuration for app 3'
}
jboss_config {
config => 'some configuration for app 4'
}
jboss_config {
config => 'some configuration for app 5'
}
#now, as all …
Run Code Online (Sandbox Code Playgroud) Puppet 使用 augeas。使用 Puppet 而不是 Augeas 本身有什么好处?
我经常使用 puppet 和 augeas 工具来配置属性文件。我的最新要求是对相当长的属性文件列表应用相同的固定更改集。所以,我想一次性完成,而不是为每个属性文件编写一个augeas。
例子:
augeas { 'change_name_whatever':
lens => 'a_customized_lens',
incl => "$path/file1.properties",
changes => $change_set,
}
augeas { 'change_name_whatever':
lens => 'a_customized_lens',
incl => "$path/file2.properties",
changes => $change_set,
}
etc...
Run Code Online (Sandbox Code Playgroud)
我想使用:
augeas { 'change_name_whatever':
lens => 'a_customized_lens',
incl => "[list of files to change],
changes => $change_set,
}
Run Code Online (Sandbox Code Playgroud)
但这是不可能的,因为 augeas 需要预加载文件。
因为我使用的是 puppet 3.8,所以我不能使用foreach类型的循环。我看到在 puppet 4 中你可以声明一个文件列表,然后循环它们并做你的事情。这很酷……但在 puppet 3 中不起作用。
那么,我有没有其他解决方案然后多次复制/粘贴相同的代码?
干杯。