Ansible Resource Modules offer various states to manage network configuration sections effectively. For example use parsed
to convert configurations into structured data, like so:
---
- name: Ansible Modules - Resource Modules (Parse)
hosts: leaf1
gather_facts: false
tasks:
- name: Parse the provided configuration
cisco.ios.ios_l3_interfaces:
running_config: "{{ lookup('file', 'leaf1_backup.cfg') }}"
state: parsed
register: l3_interfaces_parsed
- name: Print parsed configuration
debug:
var: l3_interfaces_parsed.parsed
# Output:
# $ ansible-playbook -i inventory.yaml playbooks/pb_resource_module_parse.yaml
# ...
# ok: [leaf1] =>
# l3_interfaces_parsed.parsed:
# - ipv4:
# - address: 10.1.1.1/30
# name: GigabitEthernet0/0
# - ipv4:
# - address: 10.1.2.1/30
# name: GigabitEthernet0/1
# ...