我正在尝试使用puppet来编辑jenkins config.xml.由于种种原因,我认为augeas最有意义,而且我几乎拥有我需要的东西,但格式化非常粗糙.
这是我的木偶文件:
augeas { 'jenkins_config.xml' :
incl => '/tmp/config.xml',
lens => 'Xml.lns',
context => '/files/tmp/config.xml/hudson',
changes => [
"set securityRealm/#attribute/class hudson.security.PAMSecurityRealm",
"set securityRealm/#attribute/plugin pam-auth@1.0",
"set securityRealm/serviceName/#text sshd",
],
}
Run Code Online (Sandbox Code Playgroud)
我在找什么:
<hudson>
<securityRealm class="hudson.security.PAMSecurityRealm" plugin="pam-auth@1.0">
<serviceName>sshd</serviceName>
</securityRealm>
</hudson>
Run Code Online (Sandbox Code Playgroud)
我得到了什么:
<hudson>
<securityRealm class="hudson.security.PAMSecurityRealm" plugin="pam-auth@1.0"><serviceName>sshd</serviceName>
</securityRealm>
</hudson>
Run Code Online (Sandbox Code Playgroud)
内容很好(顺便说一句,这太棒了),但阅读起来并不好玩.augeas可以为我处理缩进和换行吗?如果我必须自己做,有人可以提供缩进提示吗?我的尝试都失败了.
The short answer is you don't.
Augeas doesn't (currently) allow you to manage that, it only allows you to edit the file as it is, and uses defaults for adding new parameters. In addition, it cannot detect current identation to re-use it.
One way for you to achieve what you want would be to use a pretty-printer command, and plug it after the Augeas changes, something like:
augeas { 'manage your file':
changes => [ 'blah'],
} ~>
exec { 'pretty print file':
command => '/bin/pretty-print-cmd file',
refreshonly => true,
}
Run Code Online (Sandbox Code Playgroud)
This will trigger the pretty printing command when Augeas changes are applied. For pretty printing, you could go with xmlstarlet for example.
| 归档时间: |
|
| 查看次数: |
2376 次 |
| 最近记录: |