Skip to content

Commit

Permalink
add another resource module example (#71162)
Browse files Browse the repository at this point in the history
* Update docs/docsite/rst/network/user_guide/network_resource_modules.rst
Co-authored-by: Nilashish Chakraborty <nilashishchakraborty8@gmail.com>
  • Loading branch information
samccann committed Aug 10, 2020
1 parent e72e12a commit f4388de
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/docsite/rst/network/user_guide/network_resource_modules.rst
Expand Up @@ -150,6 +150,50 @@ The following playbook uses the :ref:`eos_l3_interfaces <eos_l3_interfaces_modul
assert:
that: not result.changed
Example: Acquiring and updating VLANs on a network device
==========================================================

This example shows how you can use resource modules to:

#. Retrieve the current configuration on a network device.
#. Save that configuration locally.
#. 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:

.. code-block:: yaml
- name: Gather VLAN information as structured data
cisco.ios.ios_facts:
gather_subset:
- '!all'
- '!min'
gather_network_resources:
- 'vlans'
2. Store the VLAN configuration locally:

.. code-block:: yaml
- name: Store VLAN facts to host_vars
copy:
content: "{{ ansible_network_resources | to_nice_yaml }}"
dest: "{{ playbook_dir }}/host_vars/{{ inventory_hostname }}"
3. Modify the stored file to update the VLAN configuration locally.

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

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

`Network Features in Ansible 2.9 <https://www.ansible.com/blog/network-features-coming-soon-in-ansible-engine-2.9>`_
Expand Down

0 comments on commit f4388de

Please sign in to comment.