Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查puppet中是否存在目录_Puppet - Fatal编程技术网

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

如何检查puppet中是否存在目录,puppet,Puppet,正在尝试使用puppet在rpi上创建autostart目录。仅当位置不存在时,它才应mkdir 以下是当前代码: exec { "mkdir_autostart": command => "mkdir /home/pi/.config/autostart", unless => "[ -d /home/pi/.config/autostart ]", path => "/usr/local/bin/:/bin/", } 以下是我得到的: err: Failed to

正在尝试使用puppet在rpi上创建autostart目录。仅当位置不存在时,它才应
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 '['
您应该使用“文件”类型:

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

您应该使用“file”类型:


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

而不是使用,除非我建议在mkdir中添加-p标志:

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

或者更好的方法是使用上面@sebastien.prudhome.

提到的Puppet的文件资源类型,而不是使用,除非我建议只在mkdir中添加-p标志:

exec { "mkdir_autostart":
  command => "mkdir -p /home/pi/.config/autostart",
  path    => "/usr/local/bin/:/bin/"
}
或者更好的方法是使用上面@sebastien.prudhome提到的Puppet的文件资源类型。

可以链接到,值得注意的是,这是幂等的。可以链接到,值得注意的是,这是幂等的。