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
任务。让我们看看里面有什么。我接受了你的回答,因为它为我指明了正确的方向。我对包含的第一组任务有疑问。非常感谢。