1. NETWORK
AUTOMATION USING
PYTHON AND ANSIBLE
SUBMITTED BY:
RIMJHIM MISHRA
0101EC211096
SUBMITTED TO:
DR. MANISH AHIRWAR
ASSOCIATE PROFESSOR, DOCSE
CS-806
2. • Network automation is the practice of automatically
configuring, managing, and operating network devices
(routers, switches, firewalls, etc.) using software.
• Instead of manual CLI changes, engineers use scripts and
orchestration tools to apply policies and updates.
• Automation brings numerous benefits: increased
efficiency, since repetitive tasks run quickly and reliably;
fewer errors, as machines eliminate typos; and lower
costs, because one engineer can manage more
infrastructure.
• Industry reports highlight rapid adoption: Gartner
predicts the share of networks with “more than half” of
tasks automated will jump from under 10% in 2023 to 30%
by 2026.
Introduction to Network
Automation
3. Importance
of Network
Automation
• Network automation has become
critical for managing complex networks
reliably and at scale. By scripting
routine tasks, network teams improve
efficiency, consistency, and uptime.
Leading vendors note that manual
changes dominate today’s networks
(up to 95%), driving costs up .
• Automation reduces human error and
operational expenses.
• It covers Python libraries (Netmiko,
NAPALM, etc.) and Ansible’s model-
driven approach (playbooks, modules)
side-by-side.
5. Why Network
Automation?
• Faster deployments and
changes
• Reduced configuration errors
• Improved compliance and
auditing
• Easier scalability and
repeatability
• Enables intent-based
networking
6. Tools for
Network
Automation
• Several tools have emerged to
support network automation:
• Python: Widely used for scripting
custom automation logic, interacting
with devices using SSH, APIs, and
libraries.
• Ansible: Open-source automation
tool for configuration management.
Uses YAML-based playbooks and is
agentless.
• Others:
• Netmiko & NAPALM: Python libraries
specifically built for network devices.
• Puppet/Chef/SaltStack: General
automation tools, less popular for
networks but still usable.
• Nornir: A Python automation
framework for complex workflows
7. Role of
Python in
Network
Automation
• Python is one of the most popular
languages for network engineers
because of its simplicity,
readability, and strong community
support. It enables engineers to:
• Write custom automation scripts
for unique environments.
• Interact with network devices via
SSH (Netmiko, Paramiko) or APIs
(RESTCONF, NETCONF).
• Build integrations with monitoring
and alerting systems.
• Python’s adaptability makes it
suitable for both small-scale and
large-scale network automation.
8. Python
Libraries
Overview
• Python has a rich set of libraries
that simplify network
automation:
• Netmiko: Provides simplified SSH
access to devices from vendors
like Cisco, Juniper, HP, etc.
• NAPALM: Multi-vendor support
with a common interface; useful
for configuration changes and
state validation.
• Paramiko: Lower-level SSH
library, flexible for secure
command execution.
• pySNMP: For SNMP-based
monitoring and management.
• Requests: Makes it easy to
interact with REST APIs for
devices supporting
RESTCONF/JSON-RPC.
9. Example
Python Script
Here’s a basic example of using
Netmiko to connect to a Cisco
device and retrieve interface
information:
from netmiko import
ConnectHandler
device = {
'device_type': 'cisco_ios',
'ip': '192.168.100.1',
'username': 'admin',
'password': 'admin123',
}
net_connect =
ConnectHandler(**device)
output =
net_connect.send_command('show
ip interface brief')
print(output)
10. Introduction
to Ansible
• Ansible is an open-source IT
automation engine that automates
tasks such as configuration
management, application
deployment, and network
provisioning.
• Unlike other tools, Ansible is
agentless, meaning it doesn’t
require software to be installed on
remote systems. It uses SSH or API
to communicate.
• Ansible is especially effective in
automating repetitive network
tasks across multiple devices using
YAML-based Playbooks.
11. Ansible
Architecture
• Control Node: The system where
Ansible is installed and
commands are executed from.
• Managed Nodes: The target
network devices or servers.
• Inventory: A file listing all
managed nodes (devices).
• Modules: Code units that Ansible
executes, like ios_config or
nxos_interface.
• Playbooks: Written in YAML,
defining the set of tasks to
execute.
• Ansible connects over SSH (or
APIs) and runs tasks
declaratively, meaning you
specify the desired state, and
Ansible ensures it’s achieved.
13. Ansible for
Network
Automation
• Ansible is increasingly used in
network automation because:
• It supports many network
platforms like Cisco IOS, NX-OS,
Arista EOS, Juniper JunOS, and
more.
• Offers vendor-specific and vendor-
neutral modules.
• Enables auditable and repeatable
deployments.
• Easy for non-programmers to
understand due to its simple YAML
structure.
• Can be integrated into DevOps
pipelines (CI/CD for networks).
16. Use Cases of
Network
Automation
• Network automation is used in a wide range of
scenarios, such as:
• Initial Configuration: Automating zero-touch
provisioning of new devices.
• Periodic Backups: Regularly backing up
configurations to central storage.
• Compliance Auditing: Ensuring devices meet
security policies.
• Bulk Changes: Rolling out ACLs or QoS settings
across multiple routers/switches.
• Monitoring Integration: Auto-generating tickets or
alerts based on network status.
17. Challenges & Best Practices
Challenges:
• Differences in CLI and APIs
across vendors
• Lack of device support or
outdated firmware
• Risk of outages due to
incorrect automation logic
• Steep learning curve for non-
programmers
Best Practices:
• Always test scripts in a lab environment
before deploying in production.
• Use Git for version control and change
tracking.
• Write modular, reusable
playbooks/scripts.
• Implement logging, validation, and
rollback options in your automation.
• Document everything and follow team
coding/automation standards.
18. Future of Network
Automation
The future of network automation is promising and evolving with technologies such as:
• AI/ML-Driven Automation: Predicting network issues and automating resolutions.
• Intent-Based Networking (IBN): Networks configure themselves based on business
intent.
• SDN and NFV: Further abstraction and automation at the network edge.
• Integration with cloud orchestration tools: Terraform, Kubernetes, and hybrid
infrastructure automation.
19. Key
Takeaways
• Network automation is crucial for modern IT
infrastructures.
• Python provides flexibility and control for custom
logic.
• Ansible enables scalable, readable, and repeatable
configuration management.
• Learning and combining both tools equips network
engineers to meet current and future demands.
• Start small, automate repetitive tasks, and scale
progressively toward a fully automated network
environment.