Last active
September 2, 2018 01:24
-
-
Save DrPsychick/12cbee2b36c82ef8441ef00af47fcadf to your computer and use it in GitHub Desktop.
ansible dict filter with attribute name same as built-in method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 'values' is a built-in method and therefore always exists. This is especially useful for "influxDB" API output from an uri command. | |
# test attribute type with selectattr('fieldname', TEST), see http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-tests | |
ansible localhost -m command -a "echo {{ [ { 'values': 'foo' }, { 'name': 'bar' } ] |selectattr('values', 'string') |map(attribute='values') |list }}" | |
# alternatively filter: | |
ansible localhost -m command -a "echo {{ [ { 'values': 'foo' }, { 'name': 'bar' } ] |rejectattr('values', 'callable') |map(attribute='values') |list }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment