Difference: AnsibleTipsTricks (7 vs. 8)

Revision 816 Dec 2021 - IvoVanGeel

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

Ansible tips & tricks

Line: 63 to 63
 Instead of match, you can also use search or regex. See: https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#testing-strings

See the Jinja2 documentation for a list of available tests: https://jinja.palletsprojects.com/en/2.9.x/templates/#list-of-builtin-tests

Added:
>
>

Apply a filter to a list of items

Use "{{ variable | map('', 'filter_option1', 'filter_option2') | list }}"

For example:

"{{ output.stdout_lines | map('regex_replace', '^(\S+)\s.*$', '\\1') | list }}"

Be careful on the context in which you use this. In some cases you must use a single backslash (displaying a variable with debug for example): '\1'

 

Filter a list of strings

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2010-2019 by LANIS