2013-11-20 31 views
1

嘗試使用puppet在rpi上創建自動啓動目錄。它只能在mkdir的位置不存在。如何檢查傀儡中是否存在目錄

下面是當前的代碼:

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聲明也嘗試過,但產生同樣的錯誤。我究竟做錯了什麼?

編輯:

添加的路徑(path => "/usr/local/bin/:/bin/",),現在得到:

err: /Stage[main]/auto::Sign/Exec[mkdir_autostart]: Could not evaluate: Could not find command '[' 

回答

5

您應該使用 「文件」 類型:

file { "/home/pi/.config/autostart": 
    ensure => directory 
} 

但是,如果出於任何原因,你想保持你的「exec」類型,使用test -d /home/pi/.config/autostart

+0

可能很好鏈接到[文件 - >確保文檔](http://docs.puppetlabs.com/references/latest/type.html#file-attribute-ensure),值得注意的是這是冪等的。 – steveax

0

而不是我們荷蘭國際集團除非我建議剛加入-p標誌的mkdir:

exec { "mkdir_autostart": 
    command => "mkdir -p /home/pi/.config/autostart", 
    path => "/usr/local/bin/:/bin/" 
} 

或更好,但只是使用如上通過@ sebastien.prudhomme提到木偶的文件資源類型。