# Please help with YAML stat/fail syntax

**URL:** <https://forum.ansible.com/t/please-help-with-yaml-stat-fail-syntax/19232>\
**Category:** Ansible Project\
**Created:** [September 10, 2015, 5:36pm UTC](https://forum.ansible.com/t/please-help-with-yaml-stat-fail-syntax/19232 "2015-09-10T17:36:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![s.lutchko](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@s.lutchko](https://forum.ansible.com/u/s.lutchko)\
**Post date:** [September 10, 2015, 5:36pm UTC](https://forum.ansible.com/t/please-help-with-yaml-stat-fail-syntax/19232/1 "2015-09-10T17:36:35Z")

</div>

Hello All,

Could you please explain why do I have error here?

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 10, 2015, 9:02pm UTC](https://forum.ansible.com/t/please-help-with-yaml-stat-fail-syntax/19232/2 "2015-09-10T21:02:42Z")

</div>

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  
&nbsp;&nbsp;tasks:

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

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

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

---

<div class="post-metadata">

**Author:** ![s.lutchko](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@s.lutchko](https://forum.ansible.com/u/s.lutchko)\
**Post date:** [September 11, 2015, 2:29pm UTC](https://forum.ansible.com/t/please-help-with-yaml-stat-fail-syntax/19232/3 "2015-09-11T14:29:21Z")

</div>

Thank you, it works.

I realize the checks look redundant, it was just attempt to study how it can be used.
