I returned from holidays only to find out that re-running an Ansible playbook against a system that has been running unchanged since the beginning the year, only been receiving software updates via openSUSE Leap’s usual channels, suddenly triggered weird unhashable type errors.
Here’s a minimum playbook that will probably work for you, but doesn’t for me anymore:
- hosts: localhost remote_user: root vars: mydict: foo: bar loo: baz tasks: - debug: msg: "{{ mydict.keys() }}"
This gives me
Unexpected templating type error occurred on ({{ mydict.keys() }}): unhashable type: 'dict'
and I get a similar error message with
unhashable type: 'list'
when trying to call
mylist.append(...)
Mind you this all doesn’t happen when installing with stock openSUSE Leap 15.5 packages, only after applying some Python update I can’t clearly identify yet, and it also happens on openSUSE Leap 15.6.
Here are some alternatives:
Instead of… | …use this |
---|---|
dict.keys() |
dict | dict2items | map(attribute='key') |
dict.items() |
dict | dict2items | map(attribute='item') |
mylist.append() |
set mylist = mylist + [ new_element ] |