s R&B, Cisco, and Ansible (Network Automation)

Listen to this Post

Network automation is revolutionizing the way IT professionals manage and secure their infrastructure. By leveraging tools like Ansible, network engineers can automate repetitive tasks, reduce human error, and improve efficiency. This article explores how Ansible integrates with Cisco devices for network automation, providing practical commands and scripts to get started.

You Should Know:

1. Ansible Basics for Network Automation

Ansible is an open-source automation tool that uses YAML-based playbooks to define tasks. Unlike traditional scripting, Ansible is agentless, making it ideal for network automation.

Install Ansible on Linux:

sudo apt update && sudo apt install ansible -y  Debian/Ubuntu 
sudo yum install ansible -y  RHEL/CentOS 

Verify Installation:

ansible --version 

2. Configuring Ansible for Cisco Devices

Ansible communicates with Cisco devices using modules like ios_command, ios_config, and nxos_command.

Sample Inventory File (`inventory.ini`):

[bash] 
router1 ansible_host=192.168.1.1 
router2 ansible_host=192.168.1.2

[cisco_routers:vars] 
ansible_connection=network_cli 
ansible_network_os=ios 
ansible_user=admin 
ansible_password=cisco123 

3. Running Ad-Hoc Commands

Execute a simple `show` command on a Cisco router:

ansible router1 -m ios_command -a "commands='show version'" -i inventory.ini 

4. Automating Configuration Changes with Playbooks

Create a playbook (`deploy_vlan.yml`) to configure VLANs:


<ul>
<li>name: Configure VLAN on Cisco Switch 
hosts: cisco_routers 
gather_facts: no 
tasks: </li>
<li>name: Add VLAN 100 
ios_config: 
lines: </li>
<li>vlan 100 </li>
<li>name IT_NETWORK 

Run the playbook:

ansible-playbook deploy_vlan.yml -i inventory.ini 

5. Securing Ansible Playbooks

Store sensitive data (like passwords) using Ansible Vault:

ansible-vault encrypt_string 'cisco123' --name 'ansible_password' 

What Undercode Say:

Network automation with Ansible and Cisco is a game-changer for IT professionals. By automating repetitive tasks, engineers can focus on strategic initiatives while minimizing errors. Key takeaways:
– Use `ios_command` for querying device states.
– Apply `ios_config` for making configuration changes.
– Secure credentials with Ansible Vault.
– Test playbooks in a lab before production deployment.

For further reading, check Cisco’s official Ansible integration guide.

Expected Output:

PLAY [Configure VLAN on Cisco Switch] 
TASK [Add VLAN 100] 
changed: [bash]

PLAY RECAP 
router1 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 

References:

Reported By: Christopherleveston94 90s – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image