Question:
In an Ansible playbook I want to run tasks if a directory does not exists.
1 2 3 4 5 |
- name: Check for java exists in /opt stat: path=/opt/jdk1.8.0_71 register: p when: p.stat.isdir is defined and p.stat.isdir |
But what must I do to ensure that the following tasks runs only if this dir does not exist?
1 2 3 |
- name: Extract java if dir not existing command: tar xzf /tmp/jdk1.8.0_71 chdir=/opt |
Answer:
1 2 3 4 |
- name: Extract java if dir not existing command: tar xzf /tmp/jdk1.8.0_71 chdir=/opt when: not p.stat.exists |