Difference: AnsibleTipsTricks (2 vs. 3)

Revision 313 Oct 2021 - IvoVanGeel

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

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 list

Use "{{ variable | default([]) + [item] }}"

Add item to dictionary

Use "{{ variable | default({}) | combine({key_name: key_value}) }}"

  -- Ivo van Geel - 21 Sep 2021
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2010-2019 by LANIS