我正在尝试使用Puppet中的augeas资源类型在xml配置文件中添加或更新用户,这里是清单:
augeas { "nexus_user_newadmin":
lens => "Xml.lns",
incl => "security.xml",
root => "/usr/local/nexus/conf",
changes => [
"defnode user /files/security.xml/security/users/user[id/#text='newadmin']",
"set $user/id/#text 'newadmin'",
"set $user/firstName/#text 'first name'",
"set $user/lastName/#text 'last name'",
"set $user/password/#text 'passhere'",
"set $user/status/#text 'active'",
"set $user/email/#text 'test@domain.com'",
],
}
xml文件如下所示:
<?xml version="1.0"?>
<security>
<users>
...
<user>
<id>deployment</id>
<firstName>Deployment</firstName>
<lastName>User</lastName>
<password>somepasshere</password>
<status>active</status>
<email>changeme1@yourcompany.com</email>
</user>
</users>
</security>
运行清单时出现以下错误:
Main/Augeas[nexus_user_newadmin]: Could not evaluate: missing string argument 3 for defnode
从puppet使用时,命令defnode看起来需要3个强制参数,但是从augtool使用时只需要2(和1个可选)。 (see my original post)
如何克服Puppet中augeas实现中的这些限制?
答案 0 :(得分:5)
那里有几个问题。
首先,defnode
在augtool
中使用可选第三个参数(值)时,此参数在Ruby / Puppet中是必需的。但是,您可以将其设置为空字符串。
其次,$user
变量由Puppet解析,因为你使用双引号,所以Augeas不接收它(它是空的)。您必须使用单引号或逃避美元符号。通常,建议在Puppet中使用单引号,除非您需要扩展变量。
第三,最好使用incl
和lens
而不是root
。您也将受益于Puppet中的自动context
:
augeas { 'nexus_user_newadmin':
lens => 'Xml.lns',
incl => '/usr/local/nexus/conf/security.xml',
changes => [
'defnode user security/users/user[id/#text="newadmin"] ""',
'set $user/id/#text "newadmin"',
'set $user/firstName/#text "first name"',
'set $user/lastName/#text "last name"',
'set $user/password/#text "passhere"',
'set $user/status/#text "active"',
'set $user/email/#text "test@domain.com"',
],
}