Ansible check directory

17 views
Skip to first unread message

Bhautik K

unread,
Dec 1, 2017, 2:45:51 PM12/1/17
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages