如何检查puppet中是否存在目录

AWi*_*ler 1 puppet

尝试使用puppet在rpi上创建自动启动目录.mkdir只有当位置不存在时才应该这样做.

这是当前的代码:

exec { "mkdir_autostart":
command => "mkdir /home/pi/.config/autostart",
unless => "[ -d /home/pi/.config/autostart ]",
path    => "/usr/local/bin/:/bin/",
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的:

err: Failed to apply catalog: Parameter unless failed on Exec[mkdir_autostart]: 
'[ -d  /home/pi/.config/autostart ]' is not qualified and no path was specified.
Please qualify the command or specify a path.
Run Code Online (Sandbox Code Playgroud)

也尝试使用onlyif语句,但产生了同样的错误.我究竟做错了什么?

编辑:

添加了路径(path => "/usr/local/bin/:/bin/",),现在获得:

err: /Stage[main]/auto::Sign/Exec[mkdir_autostart]: Could not evaluate: Could not find command '['
Run Code Online (Sandbox Code Playgroud)

小智 5

您应该使用"文件"类型:

file { "/home/pi/.config/autostart":
   ensure => directory
}
Run Code Online (Sandbox Code Playgroud)

但如果出于任何原因,您想保留"exec"类型,请使用 test -d /home/pi/.config/autostart