[WARNING]: While constructing a mapping from /etc/ansible/playbooks/touch.yml, line 2, column 3, found a duplicate dict key (tasks). Using last defined value only.

1,891 views
Skip to first unread message

Anfield

unread,
May 19, 2017, 10:38:18 AM5/19/17
to Ansible Project
I have the following playbook and I got the above error. This created the directory but not the file. Any ideas?

---
- hosts: local
  tasks:
   - name: create a file if it doesnt exist
     file:
       path: /home/ansible/touchfile.txt
       state: touch
       mode: 0755
  tasks:
   - name: create a directory if it doesnt exist
     file:
       path: /home/ansible/touchdir
       state: directory
       mode: 0755

Anfield

unread,
May 19, 2017, 10:43:35 AM5/19/17
to Ansible Project
When I comment out the directory piece and run it again, ansible will create the file


Kai Stian Olstad

unread,
May 19, 2017, 10:56:57 AM5/19/17
to ansible...@googlegroups.com
You can only have one tasks: in a play.
And as the message say only the last one will be executed.

So this is the correct syntax.
---
- hosts: local
tasks:
- name: create a file if it doesnt exist
file:
path: /home/ansible/touchfile.txt
state: touch
mode: 0755

- name: create a directory if it doesnt exist
file:
path: /home/ansible/touchdir
state: directory
mode: 0755

--
Kai Stian Olstad

Anfield

unread,
May 19, 2017, 11:03:24 AM5/19/17
to Ansible Project, ansible-pr...@olstad.com

Only one task for each playbook? Didnt know that

Anfield

unread,
May 19, 2017, 11:05:42 AM5/19/17
to Ansible Project, ansible-pr...@olstad.com
Ok, nevermind. Only one instance of the tasks:, but multiple tasks underneath. Thanks!


Reply all
Reply to author
Forward
0 new messages