我有一些function,做chroot到某个目录。 我用exectypes执行这个命令两次if if-else语句。 第一次我在then一段执行命令,第二次执行else的一些参数。 虽然if返回true – 一切都很好,但如果它返回false所以我收到错误,如chroot not found 。 我的部分代码:
define manage_users($some_variables) { some code here ... if $action == "create" { $command = "..." exec {"${nsenter} && chroot ${some_dir} /bin/bash -c '${some_command}'": path => ["/usr/sbin", "/usr/bin", "/bin"], } } #delete user else { some code .... exec { "${nsenter} && chroot ${some_dir} /bin/bash -c '${some_other_command}'": path => ["usr/sbin", "/usr/bin", "/bin"], onlyif => "...", } } }
我在做什么错呢? 在我看来,就像在then 。
你的path:
path => ["usr/sbin", "/usr/bin", "/bin"],
这应该是:
path => ["/usr/sbin", "/usr/bin", "/bin"],
注意添加/在usr/sbin 。
这是有道理的,因为它是/usr/sbin/chroot 。