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

Edit | Attach | Watch | Print version | History: r19 | r4 < r3 < r2 < r1 | Backlinks | Raw View | More topic actions...
Topic revision: r1 - 21 Sep 2021 - IvoVanGeel
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2010-2019 by LANIS