Ansible task to know if a path exists and if its a directory

0 votes
I want to write a playbook that tests whether a path exists and if its a directory. How do i write an Ansible playbook for the same?
Apr 2 in Ansible by Nisha
325 views

1 answer to this question.

0 votes

Hi @Nisha, use the stat module provided by Ansible for this:

- stat:
    path: /path/to/something
  register: p
- debug:
    msg: "Path exists and is a directory"
  when: p.stat.isdir is defined and p.stat.isdir
answered Apr 2 by Alok

Related Questions In Ansible

0 votes
1 answer

Create a directory at a specific path using ansible

To create a directory using Ansible, you ...READ MORE

answered Jan 9 in Ansible by Jason
50 views
0 votes
1 answer
0 votes
1 answer

How do I execute a shell script and then use the result in ansible

This can work out for you: - name: ...READ MORE

answered Apr 11, 2018 in Ansible by shubham
• 6,870 points
457 views
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer