Module to manage configuration sections.
Version added: 1.0.0
- Cisco IOS configurations use a simple block indent file syntax for segmenting configuration into sections. This module provides an implementation for working with IOS configuration sections in a deterministic way.
Note
- Tested against Cisco IOSXE Version 17.3 on CML.
- Abbreviated commands are NOT idempotent, see https://docs.ansible.com/ansible/latest/network/user_guide/faq.html#why-do-the-config-modules-always-return-changed-true-with-abbreviated-commands
- To ensure idempotency and correct diff the configuration lines in the relevant module options should be similar to how they appear if present in the running configuration on device including the indentation.
- This module works with connection
network_cli
. See https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>`
- For more information on using Ansible to manage Cisco devices see the Cisco integration page.
- name: Configure top level configuration
cisco.ios.ios_config:
lines: hostname {{ inventory_hostname }}
- name: Configure interface settings
cisco.ios.ios_config:
lines:
- description test interface
- ip address 172.31.1.1 255.255.255.0
parents: interface Ethernet1
- name: Configure ip helpers on multiple interfaces
cisco.ios.ios_config:
lines:
- ip helper-address 172.26.1.10
- ip helper-address 172.26.3.8
parents: "{{ item }}"
with_items:
- interface Ethernet1
- interface Ethernet2
- interface GigabitEthernet1
- name: Configure policer in Scavenger class
cisco.ios.ios_config:
lines:
- conform-action transmit
- exceed-action drop
parents:
- policy-map Foo
- class Scavenger
- police cir 64000
- name: Load new acl into device
cisco.ios.ios_config:
lines:
- 10 permit ip host 192.0.2.1 any log
- 20 permit ip host 192.0.2.2 any log
- 30 permit ip host 192.0.2.3 any log
- 40 permit ip host 192.0.2.4 any log
- 50 permit ip host 192.0.2.5 any log
parents: ip access-list extended test
before: no ip access-list extended test
match: exact
- name: Check the running-config against master config
cisco.ios.ios_config:
diff_against: intended
intended_config: "{{ lookup('file', 'master.cfg') }}"
- name: Check the startup-config against the running-config
cisco.ios.ios_config:
diff_against: startup
diff_ignore_lines:
- ntp clock .*
- name: Save running to startup when modified
cisco.ios.ios_config:
save_when: modified
- name: For idempotency, use full-form commands
cisco.ios.ios_config:
lines:
# - shut
- shutdown
# parents: int gig1/0/11
parents: interface GigabitEthernet1/0/11
# Set boot image based on comparison to a group_var (version) and the version
# that is returned from the `ios_facts` module
- name: Setting boot image
cisco.ios.ios_config:
lines:
- no boot system
- boot system flash bootflash:{{new_image}}
host: "{{ inventory_hostname }}"
when: ansible_net_version != version
- name: Render a Jinja2 template onto an IOS device
cisco.ios.ios_config:
backup: true
src: ios_template.j2
- name: Configurable backup path
cisco.ios.ios_config:
src: ios_template.j2
backup: true
backup_options:
filename: backup.cfg
dir_path: /home/user
# Example ios_template.j2
# ip access-list extended test
# permit ip host 192.0.2.1 any log
# permit ip host 192.0.2.2 any log
# permit ip host 192.0.2.3 any log
# permit ip host 192.0.2.4 any log
Common return values are documented here, the following are the fields unique to this module:
- Peter Sprygada (@privateip)