Created Donnerstag 20 Februar 2020
File/directory or link exists
- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/mdtutorials2/Documents/Ansible/prompt.yaml
register: file_details
- debug:
msg: "The file or directory exists"
when: file_details.stat.exists
File exists
- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/mdtutorials2/Documents/Ansible/prompt.yaml
register: file_details
- debug:
msg: "The file or directory exists"
when: file_details.stat.exists and file_details.stat.isreg
File not exists
...
when: file_details.stat.isreg is not defined
Directory exists
- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/mdtutorials2/Documents/Ansible/prompt.yaml
register: file_details
- debug:
msg: "The file or directory exists"
when: file_details.stat.exists and file_details.stat.isdir
Directory not exists
...
when: file_details.stat.isdir is not defined
Link exists
- hosts: all
tasks:
- name: Ansible check file exists example.
stat:
path: /Users/mdtutorials2/Documents/Ansible/prompt.yaml
register: file_details
- debug:
msg: "The file or directory exists"
when: file_details.stat.exists and file_details.stat.islnk
Link not exists
...
when: file_details.stat.islnk is not defined