Skip to content

Instantly share code, notes, and snippets.

@ssato
Last active December 30, 2019 14:04
Show Gist options
  • Save ssato/6701565f4977828e25db4962457194d6 to your computer and use it in GitHub Desktop.
Save ssato/6701565f4977828e25db4962457194d6 to your computer and use it in GitHub Desktop.
- name: Jinja 2 filter example
hosts: localhost
gather_facts: no
vars:
ansible_python_interpreter: /usr/bin/python3
input_dics:
- type: a
name: router1
- type: b
name: router2
- type: c
name: router3
selector: ac
tasks:
- name: Select dicts by selector
debug:
msg: >-
{{ input_dics | selectattr("type", "in", selector)
| map(attribute='name')
| list }}
# vim:sw=2:ts=2:et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment