Ansible with Cisco


A good point to start – Ansible User Guide.
Network modules (ios/nxos/ios-xr, aci, junos etc) – Module Index – Network Modules

IOS/NXOS Command Modules

There is are a way to run multiple commands

Very useful for debugging to show output in the terminal:

– name: show output
         var: output

Some commands require to confirm the command using prompt:

Run the command, expect the prompt and provide the “answer”:

Config commands

this is an example of creating an access-list. Pretty straight forward if familiar with IOS commands.

Using Loop inside the script

– name: configure authentication mab with loop
  connection: network_cli
  hosts: ios_devices
    – name: configure authentication mab
          – authentication mab
       parents: “{{ item }}”
        – interface GigabitEthernet0/0
        – interface GigabitEthernet0/1

For Nexus devices – netowrk_os is set to “nxos”:

NXOS allows to get the output in JSON format:

Config commands

save_change: modified
If the argument is set to modified, then the running-config will only be copied to the startup-config if it has changed since the last save to startup-config.

Other options:

  • always
  • never  (default)
  • modified
  • changed (only if the task has made a change)