Ansible Network PDF
Ansible Network PDF
Ansible Network PDF
● Timing
● Breaks
● Takeaways
What You Will Learn
Ansible is capable of handling many powerful automation tasks with the flexibility to adapt to
many environments and workflows.
Source: Gartner, Look Beyond Network Vendors for Network Innovation. January 2018. Gartner ID: G00349636. (n=64)
Automation considerations
No special coding skills needed Configuration management Uses OpenSSH & WinRM
Get productive quickly Orchestrate the app lifecycle More efficient & more secure
MANAGE YOUR ENTIRE ENTERPRISE
SYS/CLOUD ADMIN
SERVERS
NET OPS
NETWORKING
STORAGE
ADMINS STORAGE
ANSIBLE NETWORK AUTOMATION
50 700+ 12 *
Network Network Galaxy
Platforms Modules Network Roles
ansible.com/networking
galaxy.ansible.com/ansible-network
Ansible Network modules comprise 1/3 of all modules that ship with Ansible Engine
Common use cases
● Backup and restore device configurations
● Upgrade network device OS
● Ensure configuration compliance
● Apply patches to address CVE
● Generate dynamic documentation
● Discrete Tasks
○ Ensure VLANs are present/absent
○ Enable/Disable netflow on WAN interfaces
○ Manage firewall access list entries
Module code is
copied to the
managed node,
LINUX/WINDOWS
executed, then HOSTS
removed
PUBLIC / PRIVATE
CLOUD PUBLIC / PRIVATE
CMDB CLOUD
USERS
HOSTS
INVENTORY CLI
MODULES PLUGINS
NETWORK
ANSIBLE DEVICES
PLAYBOOK
PUBLIC / PRIVATE
CLOUD PUBLIC / PRIVATE
CLOUD
CMDB
MODULES PLUGINS
NETWORK
ANSIBLE DEVICES
PLAYBOOK
PUBLIC / PRIVATE
CLOUD PUBLIC / PRIVATE
CLOUD
CMDB
ANSIBLE AUTOMATION
MODULESENGINE
ARE “TOOLS IN THE TOOLKIT”
Python, Powershell, or any language
Extend Ansible simplicity to the entire stack
USERS
HOSTS
INVENTORY CLI
MODULES PLUGINS
NETWORK
ANSIBLE DEVICES
PLAYBOOK
[web]
ANSIBLE AUTOMATION ENGINE
webserver1.example.com
webserver2.example.com
USERS [db]
dbserver1.example.com
HOSTS
INVENTORY CLI
[switches]
leaf01.internal.com
leaf02.internal.com
MODULES PLUGINS
[firewalls] NETWORK
DEVICES
ANSIBLE checkpoint01.internal.com
PLAYBOOK
[lb]
f5-01.internal.com
Understanding Inventory
10.1.1.2
10.1.1.3
172.16.1.1
172.16.1.2
192.168.1.2
192.168.1.3
Understanding Inventory - Groups
There is always a group called "all" by default Groups can be nested
Inventory - variables
Group variables apply for all devices
in that group
Variable Explanation
Tags are invoked using the --tags flag while running the playbook
This is useful while working with large playbooks, when you might
want to "jump" to a specific task.
Limiting tasks within a play - or skip them!
● --skip-tags allows you to skip everything
The lineinfile module is a general purpose module that is used for manipulating file
contents.
Cleaning up (cont’d)
Cleaning up an exact line match:
Cleaning up (cont’d)
Matching using a regular expression:
Restoring the configuration
If any out of band changes were made to the device and it needs to be
restored to the last known good configuration, we could take the
following approach:
● Copy over the cleaned up configuration to the devices
● Use vendor provided commands to restore the device
configuration
*In our example we use the Cisco IOS command config replace. This
allows for applying only the differences between running and the
copied configuration
Restoring (cont’d)
- Build troubleshooting
reports
# site.yml site.yml
--- roles/
- hosts: DC ntp/
roles: tasks/
- ntp main.yml
- vlan vlan/
tasks/
main.yml
Roles - really simple, but powerful
# site.yml ntp/
--- tasks/ - name: CONFIGURE NTP
- hosts: routers main.yml ios_config:
roles: vlan/
- ntp tasks/ lines: ntp server 1.2.3.4
- vlan main.yml
● Ansible Galaxy is a
hub for finding,
reusing and sharing
Ansible roles.
● Jump-start your
automation project
with content
contributed and
reviewed by the
Ansible community.
Using parsers to generate custom reports
On most network devices, show command output is "pretty" formatted but not structured.
The Ansible network-engine role provides support for 2 text parsing engines:
● TextFSM
● Command Parser
Structured data from show commands
Exercise 3.1
Building dynamic documentation using the
command parser
The objective of this lab is to generate a dynamic documentation from the output of a device show
command.
ENGINE
Playbooks
WORKFLOW
Network
device
Network
device
Network
device
65
Next Steps
Thanks so much for joining the class. Here are some next steps on how to
get more information and join the community!
Bookmark the GitHub Project
https://www.github.com/network-automation
● Examples, samples
and demos
● Run network
topologies right on
your laptop
Chat with us
Engage with the community
● Slack
https://ansiblenetwork.slack.com
Join by clicking here https://bit.ly/2OfNEBr
● IRC
#ansible-network on freenode
http://webchat.freenode.net/?channels=ansible-network
Next Steps
● It's easy to get started
https://ansible.com/get-started
● Do it again
https://github.com/network-automation/linklight
https://network-automation.github.io/linklight/
ansible.com/tower-trial