Acquiring Current Network Device Configurations

Hello,

I’m trying to do the followings for a network switch.

(1) retrieve the current configuration of a VLAN.
(2) preserve the current VLAN configuration on the Ansible host.
(3) push the new configuration to the VLAN.

However, the existing network modules for VLAN configuration can only push the new configuration and return the current configuration in a single module execution. For example, Module ios_vlans, junos_vlans, etc.

Can I achieve what I am trying to do using any existing network modules?
If not, I would like to enhance the existing modules to allow retrieving current configuration only.

Thanks!

Hello,

This use case can be achieved through the new Resource Modules (*_vlans). The following tasks should give you an idea on how to implement it:

- name: Gather VLAN information as structured data
ios_facts:
gather_subset:
- '!all'
- '!min'
gather_network_resources:
- 'vlans'

- name: Store VLAN facts to host_vars
copy:
content: "{{ ansible_network_resources | to_nice_yaml }}"
dest: "{{ playbook_dir }}/host_vars/{{ inventory_hostname }}"

Now that you have the VLAN configuration preserved on the Ansible controller, you can update it and feed it to a task by referencing the vlans keys.

- name: Make VLAN config changes by updating stored facts on the controller.
ios_vlans:
config: "{{ vlans }}"
state: merged
tags: update_config

Thanks!