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

问题描述 投票:0回答:1

我有以下任务检查目录是否存在,如果不存在然后我创建它,稍后我检查它是否创建了更多的东西,但它失败了。我错过了什么?

- 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)]
python ansible
1个回答
1
投票

你没有重新设置sprp。你需要在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
© www.soinside.com 2019 - 2024. All rights reserved.