如何检查人偶中是否存在目录 [英] How to check if a directory exists in puppet
本文介绍了如何检查人偶中是否存在目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用 puppet 在 rpi 上创建自动启动目录.仅当该位置不存在时才应该 mkdir
.
Trying to create an autostart directory on a rpi using puppet. It is supposed to mkdir
only if the location doesn't exist.
这是当前代码:
exec { "mkdir_autostart":
command => "mkdir /home/pi/.config/autostart",
unless => "[ -d /home/pi/.config/autostart ]",
path => "/usr/local/bin/:/bin/",
}
这是我得到的:
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.
也尝试过使用 onlyif 语句,但产生了同样的错误.我做错了什么?
Also tried with onlyif statement, but that generated the same error. What am I doing wrong?
添加路径(path => "/usr/local/bin/:/bin/",
),现在得到:
Added path (path => "/usr/local/bin/:/bin/",
) and now get:
err: /Stage[main]/auto::Sign/Exec[mkdir_autostart]: Could not evaluate: Could not find command '['
推荐答案
您应该使用文件"类型:
You should use the "file" type:
file { "/home/pi/.config/autostart":
ensure => directory
}
但如果出于任何原因,您想保留exec"类型,请使用 test -d/home/pi/.config/autostart
But if for any reason, you want to keep your "exec" type, use test -d /home/pi/.config/autostart
这篇关于如何检查人偶中是否存在目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文