Please help with YAML stat/fail syntax

124 views
Skip to first unread message

s.lu...@wsmintl.com

unread,
Sep 10, 2015, 4:57:28 PM9/10/15
to Ansible Project
Hello All,

Could you please explain why do I have error here?

---
- hosts: all
  tasks:

  - name: copy the script
    copy: src=/etc/ansible/sample.pl dest=/root/sample.pl mode=0700

    stat: path=/root/sample.pl
      register: st
    fail: msg="The script file wasn't copied to server {{ansible_hostname}} {{ansible_default_ipv4.address}}."
      when: st.stat.exists != True


The error is

[root@server-03 ~]# ansible-playbook /etc/ansible/sample.yml --syntax-check
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/etc/ansible/sample.yml': line 9, column 15, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    stat: path=/root/sample.pl
      register: st
              ^ here


I tried 
- stat: ...
and 
- register: ...
but this didn't help.

Thank you very much in advance.

Brian Coca

unread,
Sep 10, 2015, 5:02:48 PM9/10/15
to Ansible Project
several errors, each task needs a -, register and when are task
directives and not part of the modules so need to be at the same
level:


- hosts: all
tasks:

- name: copy the script
copy: src=/etc/ansible/sample.pl dest=/root/sample.pl mode=0700

- stat: path=/root/sample.pl
register: st
name: checking that file is there, which is redundant if copy succeeded

- fail: msg="The script file wasn't copied to server
{{ansible_hostname}} {{ansible_default_ipv4.address}}."
when: st.stat.exists != True
name: again redundant as copy will show an error already for that
host if the script fails to be copied



--
Brian Coca

s.lu...@wsmintl.com

unread,
Sep 11, 2015, 10:29:21 AM9/11/15
to Ansible Project
Thank you, it works.

I realize the checks look redundant, it was just attempt to study how it can be used.
Reply all
Reply to author
Forward
0 new messages