问题
Trying to create an autostart directory on a rpi using puppet. It is supposed to mkdir
only if the location doesn't exist.
Here is the current code:
exec { "mkdir_autostart":
command => "mkdir /home/pi/.config/autostart",
unless => "[ -d /home/pi/.config/autostart ]",
path => "/usr/local/bin/:/bin/",
}
Here is what I get:
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.
Also tried with onlyif statement, but that generated the same error. What am I doing wrong?
EDIT:
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 '['
回答1:
You should use the "file" type:
file { "/home/pi/.config/autostart":
ensure => directory
}
But if for any reason, you want to keep your "exec" type, use test -d /home/pi/.config/autostart
回答2:
Instead of using unless I'd suggest just adding a -p flag to mkdir:
exec { "mkdir_autostart":
command => "mkdir -p /home/pi/.config/autostart",
path => "/usr/local/bin/:/bin/"
}
Or better yet just use Puppet's file resource type as mentioned above by @sebastien.prudhomme.
来源:https://stackoverflow.com/questions/20108694/how-to-check-if-a-directory-exists-in-puppet