Puppet/Augeas — ins 命令在 RH6 上有效,在 RH7 上失败

Puppet/Augeas — ins 命令在 RH6 上有效,在 RH7 上失败

/etc/sudoers我在我的 puppet 模块中构造了这个结构,在最后一个“Defaults”行之后添加了一行:

  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()]"]

有人可以帮助我了解发生了什么变化,或者我做错了什么,以便我可以让这个代码片段在两种环境中工作吗?

答案1

谢谢@raphink

augtool errors

Error in /etc/sudoers:96.12 (parse_failed)
  Iterated lens matched less than it should
  Lens: /usr/share/augeas/lenses/dist/sudoers.aug:530.10-.70:
    Last matched: /usr/share/augeas/lenses/dist/sep.aug:47.18-.40:
    Next (no match): /usr/share/augeas/lenses/dist/sudoers.aug:500.16-501.47:

所以我检查了第 96 行/etc/sudoers,它说

@includedir /etc/sudoers.d

显然,@includedir除了旧式语法之外,现在是一种有效的语法#includedir......但是(我的)augeas 镜头无法识别新版本。

(* View: includedir *)
let includedir =
  [ key /#include(dir)?/ . Sep.space . store Rx.fspath . eol ]

我把 改为@a #/etc/sudoers问题似乎解决了。

相关内容