我有以下任务,检查目录是否存在,如果不存在,则创建它,然后过一会儿,我检查它是否被创建来做更多的事情,但是失败了。我想念什么?
- 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)]
答案 0 :(得分:1)
您没有重新设置sp
和rp
。您需要在stat
任务之后重新运行setup.application.yml
模块:
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