working on playbook to check file exists

33 views
Skip to first unread message

venkat velpuri

unread,
Jul 31, 2016, 2:14:41 PM7/31/16
to Ansible Project
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

Kai Stian Olstad

unread,
Jul 31, 2016, 3:27:31 PM7/31/16
to ansible...@googlegroups.com
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

--
Kai Stian Olstad

Bill Carlson

unread,
Aug 1, 2016, 9:43:41 AM8/1/16
to Ansible Project

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

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

---
- hosts: system1,system2
  tasks:
    - name: task1
      stat: path=something
      register: stat_something


There is also a method in a playbook that breaks tasks and other items into separate files in a directory structure, see the docs as mentioned.
Reply all
Reply to author
Forward
0 new messages