Ansible populating a variable based on a json param with a json param
Q: "Populate a variable with the name of the interface when the description contains a certain word."
A: For example
- set_fact:
result: "{{ ansible_facts.ansible_network_resources.interfaces|
selectattr('description', 'search', pattern)|
map(attribute='name')|
list }}"
vars:
pattern: "LOCAL A"
gives
result:
- FastEthernet0
and
- set_fact:
result: "{{ ansible_facts.ansible_network_resources.interfaces|
selectattr('description', 'search', pattern)|
map(attribute='name')|
list }}"
vars:
pattern: "LOCAL"
gives
result:
- FastEthernet0
- GigabitEthernet1/0/1
- FastEthernet1