I’m trying to search for a specific string from a var and while it finds it, it prints the whole line and not the exact match I’m looking for. I’m running ansible 2.9
Here is what it finds: Interface GigabitEthernet0/1 “outside1”, is up, line protocol is up
And what I’m looking for is everything up to ", or better yet any specific word in that line Interface GigabitEthernet0/1 “outside1”,
Here is my template:
{% for interface in show_interface.stdout_lines[0] %}
{% if interface | regex_findall('Interface*.*\"\,',multiline=True) %}
{{interface | string}}
{% endif %}
{% endfor %}
Here is my ansible-playbook task:
---
- name: execute firewall interface review
asa_command:
commands:
- show interface | grep up
register: show_interface
- name: print var data
debug:
var: show_interface.stdout_lines
- name: format interface data with template
template:
src: firewall_format.j2
dest: ./firewall_interface_facts.txt
delegate_to: localhost
'''