我在我的 puppet 模块中有这个构造,可以在/etc/sudoers
最后一个“默认”行之后添加一行:
augeas { "sudoers.ssh_auth_sock" :
lens => "Sudoers.lns",
incl => "/etc/sudoers",
onlyif => "match Defaults/env_keep/var[. = 'SSH_AUTH_SOCK'] size==0",
changes => [
# Create a new Defaults line for the two variables
"ins Defaults after Defaults[last()]",
# Make this Defaults line a += type
"clear Defaults[last()]/env_keep/append",
# assign values to the two variables
"set Defaults[last()]/env_keep/var[1] SSH_AUTH_SOCK",
],
}
它在我的 RedHat 6 机器上完美运行
Notice: Augeas[sudoers.ssh_auth_sock](provider=augeas):
--- /etc/sudoers 2021-10-12 13:30:52.880901115 +0000
+++ /etc/sudoers.augnew 2021-10-12 13:31:28.697931561 +0000
@@ -77,6 +77,7 @@
# Defaults env_keep += "HOME"
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
+Defaults env_keep += SSH_AUTH_SOCK
## Next comes the main part: which users can run what software on
Notice: /Stage[main]/Sudoers/Augeas[sudoers.ssh_auth_sock]/returns: executed successfully
但它在我的 RedHat 7 机器上失败了:
Warning: Augeas[sudoers.ssh_auth_sock](provider=augeas): Loading failed for one or more files, see debug for /augeas//error output
Error: /Stage[main]/Sudoers/Augeas[sudoers.ssh_auth_sock]: Could not evaluate: Error sending command 'ins' with params ["Defaults", "after", "/files/etc/sudoers/Defaults[last()]"]/Error sending command 'ins' with params ["Defaults", "after", "/files/etc/sudoers/Defaults[last()]"]
有人可以帮助我了解发生了什么变化,或者我做错了什么,以便我可以让这个代码段在两种环境中都可以工作吗?