directory is exists or not

20 views
Skip to first unread message

Bhautik karkar

unread,
Dec 7, 2017, 9:56:34 AM12/7/17
to ansible...@googlegroups.com

Looking for solution. I have write below yml for if directory is exists or not but getting below error. Could you please correct me where I did mistake ?

 

- hosts: compute

  tasks:

  - name: Ansible check directory exists.

    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.isdir

 

-----------------------------

ERROR! Syntax Error while loading YAML.

 

 

The error appears to have been in '/etc/ansible/postchecklist.yml': line 7, column 4, but may

be elsewhere in the file depending on the exact syntax problem.

 

The offending line appears to be:

 

    register: p

   - debug:

   ^ here


--
Thanks & Regards,
Bhautik Karkar 
9920343224

Larry Smith

unread,
Dec 7, 2017, 11:23:50 AM12/7/17
to Ansible Project
change:
msg:"Path exists and is a directory"

to:
msg: "Path exists and is a directory"

Missing space...

Bhautik karkar

unread,
Dec 7, 2017, 1:30:27 PM12/7/17
to ansible...@googlegroups.com
Hi Smith,

Tried making space but still same error.


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 ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/91e04a50-7814-4155-806c-09e2edd1435c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Dec 7, 2017, 1:33:59 PM12/7/17
to ansible...@googlegroups.com
On 07.12.2017 19:30, Bhautik karkar wrote:
>
> Tried making space but still same error.
>

You have wrong indentation, the debug task as one space to much.
It need to be indented at the same level as the stat task.

--
Kai Stian Olstad

Larry Smith

unread,
Dec 7, 2017, 1:46:33 PM12/7/17
to Ansible Project
As @kai mentioned. Your indentation is off. Here is a workable playbook for you https://gist.github.com/mrlesmithjr/039a7bccf342e456dc6f9cbb2474c995
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Bhautik karkar

unread,
Dec 7, 2017, 2:02:15 PM12/7/17
to ansible...@googlegroups.com
Thanks Kai Stian Olstad,it's work but how we can identify small syntax error ? Which editor is good to use for ansible ?

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 ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages