Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.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
Python Ansible任务创建目录,然后检查是否存在失败_Python_Ansible - Fatal编程技术网

Python Ansible任务创建目录,然后检查是否存在失败

Python Ansible任务创建目录,然后检查是否存在失败,python,ansible,Python,Ansible,我有下面的任务,检查目录是否存在,如果不存在,那么我创建它,稍后我检查它是否是为了做更多的事情而创建的,但是它失败了。我错过了什么 - hosts: "{{ target }}" vars: shared_path: /usr/local/apps/shared releases_path: /usr/local/apps/releases tasks: - name: shared_path exists stat: path={{shared_p

我有下面的任务,检查目录是否存在,如果不存在,那么我创建它,稍后我检查它是否是为了做更多的事情而创建的,但是它失败了。我错过了什么

- hosts: "{{ target }}"
  vars:
     shared_path: /usr/local/apps/shared
     releases_path: /usr/local/apps/releases

  tasks:
   - name: shared_path exists
     stat: path={{shared_path}}
     register: sp

   - name: releases_path exists
     stat: path={{releases_path}}
     register: rp

   - include: tasks/setup.application.yml
     when: sp.stat.isdir is not defined and rp.stat.isdir is not defined

   - include: tasks/deploy.application.releases.yml
     when: sp.stat.isdir is defined and rp.stat.isdir is defined
我正在跑步:

ansible 2.7.10
  config file = /home/MYUSER/Desktop/Ansible/ansible/ansible.cfg
  configured module search path = [u'/home/MYUSER/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Sep 12 2018, 05:31:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

您没有重新设置
sp
rp
。在执行
setup.application.yml
任务后,需要重新运行
stat
模块:

  tasks:
   - name: shared_path exists
     stat: path={{shared_path}}
     register: sp

   - name: releases_path exists
     stat: path={{releases_path}}
     register: rp

   - include: tasks/setup.application.yml
     when: sp.stat.isdir is not defined and rp.stat.isdir is not defined

   - name: shared_path exists
     stat: path={{shared_path}}
     register: sp

   - name: releases_path exists
     stat: path={{releases_path}}
     register: rp

   - include: tasks/deploy.application.releases.yml
     when: sp.stat.isdir is defined and rp.stat.isdir is defined

我做到了,但也失败了。似乎任务include on
setup.application.yml
尚未完成,因此即使我删除了“when”,它也会失败。我怎么能等到上一个任务完成呢?我不确定。第二个
inculde
任务是被跳过的,还是失败了?它被跳过了。在
deploy.application.releases.yml
之前加入一个
debug
任务。让我们看看里面有什么。我接受了你的回答,因为它为我指明了正确的方向。我对包含的第一组任务有疑问。非常感谢。