Introductn To Ansible
Introductn To Ansible
Why Automation?
• Tasks in code
• Collaboration
• Eliminate errors
• Write once
• Lazines
• Etc….
Possible Used Cases Includes
• Configuration Management
• Maintenance
• Configuration Audit
• Upgradation
Configuration Management
Lets say an ISP needs to configure 100s or 1000s of vlans on n number of devices to accommodate new
customers
A customer needs to deploy a new data center or new site which consists large number of devices and variety
of vendors.
Login to all the devices one by one and run the set of command one by We can ping a set of devices with Ansible and can fetch the required
one. information like
show runn Fetching Configuration before and after the maintenance.
show version uptime of all the devices
show int status routing information
show ip ospf neighbor link status
show ip bgp neighbor
All the commands used in legacy solution can be run
in one go with Ansible on a set of devices.
ISP Maintenance/ Flap
Service restoration
Routing Neighborship, Routes
Interface status
Login to all the devices one by one and run the set of command one by We can ping a set of devices with Ansible and can fetch the required
one. information like
ping 8.8.8.8 Connectivity with Internet & Intranet
show int status uptime of all the devices
show ip ospf neighbor routing information
show ip bgp neighbor link status
show runn
show version
All the commands used in legacy solution can be run
in one go with Ansible on a set of devices.
Some other use cases can be
Configuration Audit
OS Upgradation
CentOS 7 → http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-1804.iso
Alternatively, Ansible can be installed via Python pip in a Python virtual environment. This is useful if
I want to make use of multiple versions of Ansible or if I'm operating in an environment where I do
not have rights to install things in the system path.
If we are using GNS3 to practice Ansible with networking, then we do not need to install Ansible. Its
pre-installed. We just need to configure it.
If we are using eve-ng then we need to install linux and install Ansible.
Once the Ansible is installed successfully, use following commands to verify:
which ansible -> check the availability of Ansible
version --ansible -> check which version is installed
Version
configuration file in use at etc/ansible/ansible/cfg
module search path is the default.
Once Ansible is installed go to cd /etc/ansble/ and run ll/ls it will show all the files and folders.
Ansible.cfg → Certain settings in Ansible are adjustable via a configuration file (ansible.cfg).
Hosts → Ansible works against multiple systems in your infrastructure at the same time. It does this by selecting portions of systems listed in
Ansible’s inventory, which defaults to being saved in the location /etc/ansible/hosts. You can specify a different inventory file using the -i
<path> option on the command line.
Roles → In Ansible, Role is a primary mechanism for breaking a playbook into multiple files.
Ansible
Architecture
A brief explanation of Ansible and Its parts
Ease of getting started
• An inventory of targets – hosts file with target hosts (network devices)
• A state to assert – tasks (fetching information or configuration)
• Credential to log into a device – works on SSH which is already open in the network
Inventory
A set of potential target hosts to execute tasks on. Inventories are not specifically tied to a set of Ansible instructions.
Multiple inventories can exist and be used at execution time.
[access-switches]
as-01 as-01
as-02 as-02
cs-01 [core-switches]
cs-02 cs-01
cs-02
Hosts or groups are used in patterns as an entity to target or as an entity to skip from within a target. Patterns support wild
cards and even regular expressions.
. ---
- name: Get ARP
hosts: core-switches
Playbook and gather_facts: false
tasks:
Its - name: Show ARP
Components raw: show arp