I have try below task to check if directory is exist but not able to run.
-------------------------------
# ansible --version
ansible 2.2.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
---------------------------------------------
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/etc/ansible/postchecklist.yml': line
19, column 10, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Check if path exist
stat: path= /etc/yum.repos.d
^ here
--------------------------------------------------
name: Ansible check directory
hosts: compute
remote_user: root
become: true
- name: Ansible check directory exists example.
stat:
path: /etc/yum.repos.d
register: files_to_delete
- debug:
msg: "It is a directory"
when: files_to_delete.stat.exists and files_to_delete.stat.isdir
- stat: path=/etc/yum.repos.d
register: p
- debug:
msg:"Path exists and is a directory"
when: p.stat.isdir is defined and p.stat.isdi
-----------------------------------------------------------------
- name: Check if path exist
stat: path= /etc/yum.repos.d
register: check_path
- name: It exists
debug: msg='Yay, the path exists!'
when: check_path.stat.exists
- name: It doesn't exist
debug: msg="Boohoo, the path doesn't exist..."
when: check_path.stat.exists == false
Regards,
Bhautik
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/1f4db629-ae08-4cf3-a1b7-2aa7371bda96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.