Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Ansible tips & tricks | ||||||||
Line: 54 to 54 | ||||||||
Extract subitems from list of dictionaries | ||||||||
Changed: | ||||||||
< < | Use "{{ variable | map(attribute='keyname') | list }}" | |||||||
> > | Use "{{ variable | map(attribute='key_name') | list }}" | |||||||
Select items from list of dictionaries | ||||||||
Changed: | ||||||||
< < | Use "{{ variable | selectattr('keyname', 'match', 'value') | list }}" | |||||||
> > | Use "{{ variable | selectattr('key_name', 'match', 'value') | list }}" | |||||||
Instead of match, you can also use search or regex. See: https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#testing-strings
Sort list of dictionaries by subitem | ||||||||
Changed: | ||||||||
< < | Use "{{ variable | sort(attribute='keyname') }}" | |||||||
> > | Use "{{ variable | sort(attribute='key_name') }}"
Add item to listUse "{{ variable | default([]) + [item] }}"Add item to dictionaryUse "{{ variable | default({}) | combine({key_name: key_value}) }}" | |||||||
-- Ivo van Geel - 21 Sep 2021 |