使用 puppet 的 augeas 功能我想修改配置文件:
/etc/ssh/sshd_config
没有 puppet,我尝试使用 Augeas 的“augtool”,发现有几行似乎可行:
augtool> set /files/etc/ssh/sshd_config/Match[1]/Condition/User "bill","ben"
augtool> set /files/etc/ssh/sshd_config/Match/Settings/PasswordAuthentication "no"
augtool> save
虽然它似乎工作正常,但我真的不明白 [1] 在这里的用途。
我尝试将这些线条放入 Puppet 中,但没有成功:
augeas { "sshd_config":
context => "/files/etc/ssh/sshd_config",
changes => [
'set Match[1]/Condition/User "bill","ben"',
'set Settings/PasswordAuthentication "no"',
],
}
它给出了错误:错误:/Stage[main]/Samipermissions/Augeas[sshd_config]:无法评估:保存失败,请参阅调试
在调试模式下运行 Puppet 告诉我同样的事情。
有人知道这是如何工作的吗?
谢谢m0dlx。您的回答使我摆脱了我遇到的错误,但是我认为我仍然对匹配数组感到有些迷茫。使用“augtool”我可以做到以下几点:
set /files/etc/ssh/sshd_config/Match[1]/Condition/User "neil","nigel"
set /files/etc/ssh/sshd_config/Match[1]/Settings/PasswordAuthentication "no"
set /files/etc/ssh/sshd_config/Match[2]/Condition/User "yvonne","yvette"
set /files/etc/ssh/sshd_config/Match[2]/Settings/PasswordAuthentication "yes"
在配置文件中显示为:
Match User neil,nigel
PasswordAuthentication no
Match User yvonne,yvette
PasswordAuthentication yes
这是完美的。我将其翻译为 Puppet:
augeas { "sshd_config":
context => "/files/etc/ssh/sshd_config",
changes => [
'set Match[1]/Condition/User "neil","nigel"',
'set Match[1]/Settings/PasswordAuthentication "no"',
'set Match[2]/Condition/User "yvonne","yvette"',
'set Match[2]/Settings/PasswordAuthentication "yes"',
],
}
但是配置文件中的结果却大不相同:
Match User neil
PasswordAuthentication no
Match User yvonne
PasswordAuthentication yes