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, 2019 in Ansible by Nisha
4,015 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, 2019 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, 2019 in Ansible by Jason
118 views
0 votes
1 answer
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,400 points
412 views
0 votes
1 answer
0 votes
1 answer

Ansible task to determine if a path exists and is a symlink

Hi @neha, you can write your task ...READ MORE

answered Apr 2, 2019 in Ansible by Alok
715 views
0 votes
1 answer