Anas Tarsha presented on using Ansible for network automation. Ansible is an open source automation tool that is agentless and uses simple YAML files called playbooks to execute tasks sequentially. It can be used to generate device configurations, push configurations, collect running configs, upgrade devices, and more. Ansible modules run Python code directly on network devices to perform tasks. The demo showed using Ansible modules like ping, ios_command, and junos_command to execute show commands and change the hostname on both IOS and Junos devices. Additional resources were provided to learn more about using Ansible for network automation.
2. Anas Tarsha
• Network/Cloud Architect, CCIE
• Areas of focus: data center, cloud, and network
automation
• BANOG founder & organizer
• Follow me on Twitter @AnasTarsha
• Blog: AnasTarsha.com
3. Agenda
• About Ansible
• Use Cases
• How Ansible Works?
• Install Ansible
• Run Ansible
• Live Demos
4. What Is Ansible?
• IT Automation and configuration management tool
• Emerged in 2012 to initially deploy Linux
applications; support for networking modules was
added in release 2.x
• Open source; code available on Github
• Often compared to Chef, Puppet, and SaltStack
5. Why Ansible?
• Agentless and extensible
• You don’t need to be a programmer to get started
• Saves time (maybe)
• Speed, but do you care?
• Predictable outcome; reduces human error
6. Ansible Use Cases
• Generating device configurations
• Saving and collecting running device
configurations
• Pushing out configurations to the network
• Upgrading devices
7. How Does Ansible Work?
Ansible
Control Host
Inventory File
sw1
r1
fw1
Network
Device
Playbook
play 1
hosts: all
- task 1
- task 2
SSH
Netconf
eAPI
NX-API
Python code
executed here
8. Install Ansible
• Easy to install using utilities like pip, yum, apt
• Runs only on Linux-based machines
• Official Install Guide:
http://docs.ansible.com/ansible/intro_installation.html
9. Ansible Playbooks
• Describe a policy you want to enforce or tasks you want o execute on your
devices
• Expressed in YAML
• “We use YAML because it is easier for humans to read and write than other
common data formats like XML or JSON” — ansible.com
• Each playbook can have a play or more and each play can have one task or more
• Tasks are executed sequentially
- name: example playbook
hosts: junos
tasks:
- tasks you want to automate
10. Ansible Modules
• They do the actual work in playbook; take arguments
• Mostly written in Python and return JSON data
• Core modules come installed with Ansible; non-core modules can be installed manually
• Run in playbook, but can run single module from command line
• Use ansible-doc module_name command for help
• Ansible Networking Modules http://docs.ansible.com/ansible/list_of_network_modules.html
• Example:
- name: collect default set of facts and configuration in XML & JSON format
junos_facts:
config: yes
config_format: xml
11. Run Ansible
1. Create an inventory file and define your devices:
[ios]
router1 ansible_host=192.168.0.201
switch1 ansible_host=192.168.0.203
[junos]
router2 ansible_host=192.168.0.130
2. Create a playbook:
- name: ping Google’s DNS from the device
hosts: ios
tasks:
- ios_command:
commands: ping 8.8.8.8
….. <omitted>
3. Run the playbook: ansible-playbook myPlaybook.yml
Sample inventory file:
2 groups, total of 3
network devices defined
Sample playbook:
Include plays and tasks
to execute
12. Live Demos
• Vagrant running on macOS Sierra to provision the
host VM
• Ansible 2.2 running on Ubuntu 14.4 LTS
• Cisco CSR 1000v and Juniper vSRX
• SSH is enabled on CSR; Netconf is enabled on
vSRX
17. Demo 5:
show_arp_result_junos.yml
---
- hosts: junos
tasks:
- junos_command:
commands: show arp
provider: "{{ netconf }}"
register: result
- debug: var=result
junos module with
required arguments
18. Additional Resources
• Network Automation with Ansible, report by Jason Edelman (free,
login required)
https://www.oreilly.com/learning/network-automation-with-ansible
• Up and Running with Ansible (free eBook)
https://ipfs.io/ipfs/
QmTJaLdhUW6jTdXGFoqv7wZe5KguBi5F2u4ihBdrUMVPhw
• Ivan Pepeljak’s Blog http://ipspace.net
• Learn Linux: video training from safaribooksonline.com or
lynda.com or pluralsight.com