# working on playbook to check file exists

**URL:** <https://forum.ansible.com/t/working-on-playbook-to-check-file-exists/22156>\
**Category:** Ansible Project\
**Created:** [July 28, 2016, 8:20pm UTC](https://forum.ansible.com/t/working-on-playbook-to-check-file-exists/22156 "2016-07-28T20:20:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkat\_velpuri](https://avatars.discourse-cdn.com/v4/letter/v/f475e1/32.png) [@venkat\_velpuri](https://forum.ansible.com/u/venkat_velpuri)\
**Post date:** [July 28, 2016, 8:20pm UTC](https://forum.ansible.com/t/working-on-playbook-to-check-file-exists/22156/1 "2016-07-28T20:20:13Z")

</div>

I am new to ansible getting error

ansible-playbook -vvvv -i apphosts file.yml  
ERROR: parse error: playbooks must be formatted as a YAML list, got \<type ‘dict’\>

tasks:

- name: Check that the somefile.conf exists  
stat: path=/etc/file.txt  
register: stat\_result

- name: Create the file, if it doesnt exist already  
file: path=/etc/file.txt state=touch  
when: stat\_result.stat.exists == False

can any one please help me to sort this problem

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 31, 2016, 7:26pm UTC](https://forum.ansible.com/t/working-on-playbook-to-check-file-exists/22156/2 "2016-07-31T19:26:55Z")

</div>

This is a task list not a playbook, I suggest reading this short intro and you'll learn the difference.

[https://docs.ansible.com/ansible/playbooks\_intro.html](https://docs.ansible.com/ansible/playbooks_intro.html)

---

<div class="post-metadata">

**Author:** ![Bill\_Carlson](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@Bill\_Carlson](https://forum.ansible.com/u/Bill_Carlson)\
**Post date:** [August 1, 2016, 1:34pm UTC](https://forum.ansible.com/t/working-on-playbook-to-check-file-exists/22156/3 "2016-08-01T13:34:55Z")

</div>

Assuming that is your full playbook file, it needs more than tasks.

Sample of a working file, read up for explanation of each portion:
