Ansible tips & tricks
Ansible data types
integer: 3211241
boolean: true/false
float: 3.141592653
string: "qwerty"
list:
- "item 1"
- "item 2"
dictionary:
key1: "value 1"
key2: "value 2"
manipulating data
Extract subitems from list of dictionaries
Use "{{ variable | map(attribute='keyname') | list }}"
Select items from list of dictionaries
Use "{{ variable | selectattr('keyname', '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
Use "{{ variable | sort(attribute='keyname') }}"
--
Ivo van Geel - 21 Sep 2021