
使用 Puppet 版本
掌握:木偶伺服器 6.7
客戶:傀儡特工 6.10
我在其他模組中有其他 Augeas 程式碼,工作得很好。
範例 sssd.conf
[sssd]
services = nss, sudo, pam, ssh
config_file_version = 2
domains = abc.def.net
[domain/abc.def.net]
cache_credentials = True
id_provider = ipa
auth_provider = ipa
access_provider = ipa
ipa_hostname = xxx.abc.def.net
...
我需要更新/驗證 [domain/abc.def.net] 部分中的 ipa_hostname 值。我不明白我的這個 augeas 代碼做錯了什麼
augeas { "sssd.conf":
context => "/files/etc/sssd/sssd.conf",
changes => [
"set ipa_hostname xxx",
],
notify => Service["sssd"]
}
這是調試輸出:
Debug: Augeas[sssd.conf](provider=augeas): Opening augeas with root /, lens path , flags 64
Debug: Augeas[sssd.conf](provider=augeas): Augeas version 1.12.0 is installed
Debug: Augeas[sssd.conf](provider=augeas): Will attempt to save and only run if files changed
Debug: Augeas[sssd.conf](provider=augeas): sending command 'set' with params ["/files/etc/sssd/sssd.conf/ipa_hostname", "no"]
Debug: Augeas[sssd.conf](provider=augeas): Put failed on one or more files, output from /augeas//error:
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error = put_failed
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error/path = /files/etc/sssd/sssd.conf/
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error/lens = /opt/puppetlabs/puppet/share/augeas/lenses/dist/sssd.aug:33.13-.53:
Debug: Augeas[sssd.conf](provider=augeas): /augeas/files/etc/sssd/sssd.conf/error/message = Failed to match tree under /
{ "target" = "sssd" }
{ "target" = "domain/test.hfgs.net" }
{ "target" = "nss" }
{ "target" = "pam" }
{ "target" = "sudo" }
{ "target" = "autofs" }
{ "target" = "ssh" }
{ "target" = "pac" }
{ "ipa_hostname" = "xxx" }
with pattern
( { /#comment/ = /[^\t\n\r ].*[^\t\n\r ]|[^\t\n\r ]/ }
| { })*
{ /target/ = /[^]\n\r]+/ }*
Debug: Augeas[sssd.conf](provider=augeas): Closed the augeas connection
Error: /Stage[main]/Testaugeas/Augeas[sssd.conf]: Could not evaluate: Save failed, see debug output for details
答案1
花了幾天時間,但我終於弄清楚了。我添加了一些額外的程式碼來展示如何尋址同一文件中的另一個部分。希望這可以幫助。
$domain = abc.net
augeas { "sssd.conf ipa_hostname":
lens => 'sssd.lns',
incl => '/etc/sssd/sssd.conf',
changes => [
"set target[ . = 'sssd']/services 'nss, sudo, pam, ssh'",
"set target[ . = 'sssd']/config_file_version 2",
"set target[ . = 'sssd']/domains ${domain}",
"set target[ . = 'domain/${domain}']/ipa_hostname ${hostname}.${domain}",
],
notify => Service["sssd"]
}