Warning when building a mapping in Ansible

Whenever I run my game, the following warning appears:

[WARNING]: when building the mapping from /etc/ansible/roles/foo/tasks/main.yml line 17, column 3, a duplicate dict key (file) was found. Use only the last defined value.

The corresponding part of my main.yml in the task folder looks like this:

(line 17 is the task of cleaning files that seem a bit off, so I think the problem is with the previous <script line)

- name: Run script to format output script: foo.py {{ taskname }} /tmp/fcpout.log - name: Clean temp files file: path=/tmp/fcpout.log state=absent 

And my vars file:

 --- my_dict: {SLM: "114", Regular: "255", Production: "1"} taskid: "{{my_dict[taskname]}}" 

To run my book, I:

 ansible-playbook playbooks/foo.yml --extra-vars "server=bar taskname=SLM" 

What I'm trying to do is take the command line arguments, set the hosts: with the "server" parameter, get the name of the task and find out which identifier it belongs to. This identifier is used as the first input of my python script, which is started remotely.

Playbook works fine, but I donโ€™t understand why I am getting a warning. Can someone explain what is wrong here?

+7
source share
2 answers

Are you sure that around line 17 no more? This warning is triggered when there are two identical keys in the task (or even somewhere in the dict).

The warning states that there are two file keys, suggesting that the task look like this:

 - name: Clean temp files file: ... file: ... 

A common mistake is that people forget to start a new list item for the next task. The following would be true: otherwise:

 - name: Clean temp files file: ... - file: ... 

I noticed that Ansible sometimes gets lines or even files in error messages. I saw how he complained about tasks/main.yml , while the problem really was in handlers/main.yml . If such a task with duplicate file keys is not found next to this line, search for the entire file or even other files for it. If nothing like this is found, then it turns out that you found a bug in Ansible. In this case, you must reinstall it on github .

+10
source

I came across this warning due to the use of duplicate options in the module. For example, by chance I used the "host" option 2 times in the module definition, as shown below:

  name: Create NEW DB User mysql_user: name: NEW USER NAME login_user: root login_password: Root Passwd password: NEW USER'S PASSWD host: localhost priv: 'DB NAME.*:ALL,GRANT' state: present host: localhost 

The warning disappeared due to missing one of the host parameters.

0
source

Source: https://habr.com/ru/post/1244901/


All Articles