Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
我是否可以在ansible中设置任务,使其仅在文件夹存在时运行?_Ansible - Fatal编程技术网

我是否可以在ansible中设置任务,使其仅在文件夹存在时运行?

我是否可以在ansible中设置任务,使其仅在文件夹存在时运行?,ansible,Ansible,是否可以将ansible playbook中的任务设置为仅在服务器上存在某个文件夹或文件时运行?如果可能的话,我该怎么做?可以检查服务器上是否存在文件夹,并且可以使用此信息控制任务的执行 - name: get stats for a folder stat: path=/path/to/folder register: stat_result - name: Doing something if folder exists command: do something when:

是否可以将ansible playbook中的任务设置为仅在服务器上存在某个文件夹或文件时运行?如果可能的话,我该怎么做?

可以检查服务器上是否存在文件夹,并且可以使用此信息控制任务的执行

- name: get stats for a folder
  stat: path=/path/to/folder
  register: stat_result
- name: Doing something if folder exists
  command: do something
  when: stat_result.stat.isdir|d(False)
更多信息:

  • |d
    |default
    的缩写,如果未定义“isdir”,则提供默认值

谢谢,这正是我所想的样子。