The Ansible 2.8 upgrade brought a few failing Playbooks. I ran into the following error:
TASK [Demo Task] **************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute '_ansible_item_label'\n\nThe error appears to be in '/path/to/ansible/playbook.yml': line 76, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Demo Task\n ^ here\n"}
Well, seems like another upgrade with another major change. Don’t you like that?
Ok, let’s see, what is the problem here? I’m running the following task, with a loop, and want to control the label which is printed. demos.results
contains a structure with keys. In Ansible < 2.8, _ansible_item_label
will just print the key which Ansible is currently looping over.
|
|
However _ansible_item_label
is no longer available. The “new”" way to do this is:
|
|
Know and print the key name, and also add a default in case it’s empty.
And if you want your playbook to run on both Ansible < 2.8 and Ansible >= 2.8, you need two blocks of code:
|
|