After completing this section, you should be able to:
Back up network device configurations.
Implement Move/Add/Change/Delete (MACD) changes using Ansible os_config modules.
Ansible *os_config modules make it easy to back up network device configurations:
Setting the backup argument to yes causes the *os_config module to create a full backup of the current running configuration from the remote device.
The backup file is written to the backup/ directory in the playbook root directory or role root directory, if the playbook is part of an Ansible Role.
If the directory does not exist, it is created.
Backup files are named using this format:
<inventory_hostname>
_config.yyyy-mm-dd@HH:MM:SS.
The file format of the backed up running configuration is platform dependent: an ios_config backup generates a text file containing an IOS running configuration, a vyos_config backup generates a text file containing a VyOS running configuration, and so forth.
Ad hoc commands can be used to back up running configurations on an on-demand basis.
An ad hoc command using the ios_config module:
$ansible -i inventory --ask-vault-pass -m ios_config -a 'backup=yes' cs01
The same example using the vyos_config module:
$ansible -i inventory --ask-vault-pass -m vyos_config -a 'backup=yes' spine01
Playbooks can drive the act of backing up network device configurations. It is often useful to have a play in which a task that modifies the configuration is preceded by a task that backs up the running configuration before the change.
A play with a task that uses the vyos_config module:
- hosts: vyos
tasks:
- name: Backup VyOS running config
vyos_config:
backup: yes
A play with a task that uses the ios_config module:
- hosts: ios
tasks:
- name: Backup IOS running config
ios_config:
backup: yes