├── .gitignore ├── README.md ├── ansible.cfg ├── backup.yml ├── change_config.yml ├── group_vars ├── arista.yml ├── cisco.yml └── juniper.yml ├── hosts ├── images └── networkautomation.png └── show_interfaces.yml /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Network Automation - Agnostic Examples 2 | This Github repository is for showcasing [cli_command](https://docs.ansible.com/ansible/latest/modules/cli_command_module.html) and [cli_config](https://docs.ansible.com/ansible/latest/modules/cli_config_module.html) agnostic network automation modules for the [network_cli connection plugin](https://docs.ansible.com/ansible/latest/plugins/connection/network_cli.html). 3 | 4 | ## Playbooks 5 | 6 | - [show_interfaces.yml](show_interfaces.yml) - this playbook issues `show ip interface brief` on Cisco IOS and Arista EOS, and `show interface terse` on Juniper Junos. Then displays the output to the terminal window. 7 | - [backup.yml](backup.yml) - performs a backup of the running configuration on Arista EOS, Cisco IOS and Juniper Junos. 8 | 9 | ## Explanation of Additional Files 10 | 11 | - ansible.cfg - this is the [Ansible Configuration File](https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html#configuration-file). This is not required but points to my inventory, in this case a file called `hosts` 12 | - hosts - this is an INI formatted [inventory file](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html). This is to be used as an example. 13 | - group_vars - this is a directory that contains [variables separated by group](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html). It is recommended to have a group per network platform type to store platform specific variables. 14 | 15 | --- 16 | ![Red Hat Ansible Automation](images/networkautomation.png) 17 | 18 | - [Red Hat® Ansible® Network Automation](https://www.ansible.com/networking): automate networking devices from Arista (EOS), Cisco (IOS, IOS XR, NX-OS), Juniper (JunOS), Open vSwitch, and VyOS and many more! Includes [Ansible Tower](https://www.ansible.com/tower) curated content specifically for network use cases. 19 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | stdout_callback = yaml 3 | host_key_checking = False 4 | retry_files_enabled = False 5 | inventory = hosts 6 | [persistent_connection] 7 | connect_timeout = 60 8 | command_timeout = 60 9 | -------------------------------------------------------------------------------- /backup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: BACKUP ALL CONFIGS 3 | hosts: routers 4 | gather_facts: false 5 | 6 | tasks: 7 | 8 | - name: RETRIEVE CONFIGURATION 9 | cli_command: 10 | command: "{{backup}}" 11 | register: backup 12 | 13 | - name: MOVE TO FILE 14 | copy: 15 | content: "{{backup.stdout}}" 16 | dest: "{{inventory_hostname}}.backup" 17 | -------------------------------------------------------------------------------- /change_config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: CHANGE CONFIGURATION 3 | hosts: routers 4 | gather_facts: false 5 | 6 | tasks: 7 | 8 | - name: LOAD NTP CONFIGURATION 9 | cli_config: 10 | config: "{{ntp_commands}}" 11 | notify: 12 | - SAVE CONFIGURATION 13 | 14 | handlers: 15 | 16 | - name: SAVE CONFIGURATION 17 | cli_command: 18 | command: "{{save}}" 19 | -------------------------------------------------------------------------------- /group_vars/arista.yml: -------------------------------------------------------------------------------- 1 | show_interfaces: "show ip interface brief" 2 | backup: "show running-config" 3 | save: "copy running-config startup-config" 4 | ntp_commands: ntp server 192.168.1.1 5 | -------------------------------------------------------------------------------- /group_vars/cisco.yml: -------------------------------------------------------------------------------- 1 | show_interfaces: "show ip interface brief" 2 | backup: "show running-config" 3 | save: "write memory" 4 | ntp_commands: ntp server 192.168.1.1 5 | -------------------------------------------------------------------------------- /group_vars/juniper.yml: -------------------------------------------------------------------------------- 1 | show_interfaces: "show interface terse" 2 | backup: "show configuration" 3 | -------------------------------------------------------------------------------- /hosts: -------------------------------------------------------------------------------- 1 | [routers:children] 2 | cisco 3 | juniper 4 | arista 5 | 6 | [routers:vars] 7 | ansible_ssh_private_key_file=/home/student1/.ssh/aws-private.pem 8 | 9 | [cisco] 10 | rtr1 ansible_host=35.182.95.156 private_ip=172.16.66.39 11 | 12 | [juniper] 13 | rtr3 ansible_host=35.183.65.165 private_ip=172.16.172.11 14 | 15 | [arista] 16 | rtr2 ansible_host=35.183.81.37 private_ip=172.17.2.86 17 | rtr4 ansible_host=35.182.145.28 private_ip=172.17.154.1 18 | 19 | [cisco:vars] 20 | ansible_user=ec2-user 21 | ansible_network_os=ios 22 | ansible_connection=network_cli 23 | 24 | [juniper:vars] 25 | ansible_user=jnpr 26 | ansible_network_os=junos 27 | ansible_connection=network_cli 28 | 29 | [arista:vars] 30 | ansible_user=ec2-user 31 | ansible_network_os=eos 32 | ansible_connection=network_cli 33 | ansible_become=true 34 | ansible_become_method=enable 35 | -------------------------------------------------------------------------------- /images/networkautomation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/network-automation/agnostic_example/c10735967ec02d4f82420c5bd3deecec50efe15d/images/networkautomation.png -------------------------------------------------------------------------------- /show_interfaces.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: RUN COMMAND AND PRINT TO TERMINAL WINDOW 3 | hosts: routers 4 | gather_facts: false 5 | 6 | tasks: 7 | 8 | # The ansible_network_os is stored as a group variable in inventory 9 | # It is recommended to store variables you use to connect TO THE DEVICE 10 | # in inventory. Variables you use to run on or configure on the device in 11 | # group_var folder stucture. 12 | # More on group_vars here: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html 13 | - debug: 14 | msg: "{{ansible_network_os}}" 15 | 16 | # The show_interfaces command is stored under group_vars 17 | # e.g. group_vars/cisco.yml which contains "show ip interface brief" 18 | - debug: 19 | msg: "{{show_interfaces}}" 20 | 21 | - name: RUN SHOW COMMAND 22 | cli_command: 23 | command: "{{show_interfaces}}" 24 | register: command_output 25 | 26 | - name: PRINT TO TERMINAL WINDOW 27 | debug: 28 | msg: "{{command_output.stdout}}" 29 | --------------------------------------------------------------------------------