+

Search Tips   |   Advanced Search

Network Resource Modules

Ansible network resource modules simplify and standardize how you manage different network devices. Network devices separate configuration into sections (such as interfaces and VLANs) that apply to a network service. Ansible network resource modules take advantage of this to allow you to configure subsections or resources within the network device configuration. Network resource modules provide a consistent experience across different network devices.


Network resource module states

You use the network resource modules by assigning a state to what you want the module to do. The resource modules support the following states:

merged

Ansible merges the on-device configuration with the provided configuration in the task.

replaced

Ansible replaces the on-device configuration subsection with the provided configuration subsection in the task.

overridden

Ansible overrides the on-device configuration for the resource with the provided configuration in the task. Use caution with this state as you could remove your access to the device (for example, by overriding the management interface configuration).

deleted

Ansible deletes the on-device configuration subsection and restores any default settings.

gathered

Ansible displays the resource details gathered from the network device and accessed with the gathered key in the result.

rendered

Ansible renders the provided configuration in the task in the device-native format (for example, Cisco IOS CLI). Ansible returns this rendered configuration in the rendered key in the result. Note this state does not communicate with the network device and can be used offline.

parsed

Ansible parses the configuration from the running_configuration option into Ansible structured data in the parsed key in the result. Note this does not gather the configuration from the network device so this state can be used offline.


Using network resource modules

This example configures the L3 interface resource on a Cisco IOS device, based on different state settings.

The following table shows an example of how an initial resource configuration changes with this task for different states.

Resource starting configuration task-provided configuration (YAML) Final resource configuration on device

    interface loopback100
     ip address 10.10.1.100 255.255.255.0
     ipv6 address FC00:100/64
    

    config:
    - ipv6:
     - address: fc00::100/64
     - address: fc00::101/64
     name: loopback100
    
merged

    interface loopback100
     ip address 10.10.1.100 255.255.255.0
     ipv6 address FC00:100/64
     ipv6 address FC00:101/64
    
replaced

    interface loopback100
     no ip address
     ipv6 address FC00:100/64
     ipv6 address FC00:101/64
    
overridden
Incorrect use case. This would remove all interfaces from the device
(including the mgmt interface) except
the configured loopback100
deleted

    interface loopback100
     no ip address
    

Network resource modules return the following details:


Example: Verifying the network device configuration has not changed

The following playbook uses the arista.eos.eos_l3_interfaces module to gather a subset of the network device configuration (Layer 3 interfaces only) and verifies the information is accurate and has not changed. This playbook passes the results of arista.eos.eos_facts directly to the arista.eos.eos_l3_interfaces module.


Example: Acquiring and updating VLANs on a network device

This example shows how you can use resource modules to:

  1. Retrieve the current configuration on a network device.

  2. Save that configuration locally.

  3. Update that configuration and apply it to the network device.

This example uses the cisco.ios.ios_vlans resource module to retrieve and update the VLANs on an IOS device.

  1. Retrieve the current IOS VLAN configuration:

  1. Store the VLAN configuration locally:

  1. Modify the stored file to update the VLAN configuration locally.

  2. Merge the updated VLAN configuration with the existing configuration on the device:


See also

Network Features in Ansible 2.9

A introductory blog post on network resource modules.

Deep Dive into Network Resource Modules

A deeper dive presentation into network resource modules.

Next Previous