This Task automates the configuration of Cisco and Juniper network devices using Ansible. It ensures consistency, eliminates manual errors, and simplifies managing VLANs, ACLs, and routing protocols such as OSPF and BGP.
+--------------------+ | Network Admin | +--------------------+ | v +--------------------+ | Ansible Tower | (Automation and Scheduling) +--------------------+ | v +--------------------+ | Network Devices | (Cisco Switches, Juniper Routers) +--------------------+ | v +--------------------+ | Monitoring System | (Prometheus & Grafana) +--------------------+
1. Install Ansible on the control node:
sudo apt update && sudo apt install ansible -y
2. Install network modules:
ansible-galaxy collection install cisco.ios juniper.junos
3. Create an inventory file (inventory.yml) with network devices:
all:
hosts:
cisco_switch:
ansible_host: 192.168.1.1
ansible_user: admin
ansible_password: password
ansible_network_os: cisco.ios
juniper_router:
ansible_host: 192.168.1.2
ansible_user: admin
ansible_password: password
ansible_network_os: juniper.junos
Create an Ansible playbook (vlan_config.yml) to configure VLANs.
- name: Configure VLANs on Cisco Switch
hosts: cisco_switch
gather_facts: no
tasks:
- name: Create VLANs
cisco.ios.ios_config:
lines:
- vlan 10
- name HR_VLAN
- vlan 20
- name FINANCE_VLAN
save_when: changed
Run the playbook:
ansible-playbook vlan_config.yml
Create an Ansible playbook (acl_config.yml) to apply ACLs.
- name: Configure ACL on Cisco Switch
hosts: cisco_switch
gather_facts: no
tasks:
- name: Apply ACL for security
cisco.ios.ios_config:
lines:
- ip access-list standard BLOCK_SSH
- deny tcp any any eq 22
- permit ip any any
save_when: changed
Run the playbook:
ansible-playbook acl_config.yml
Create a playbook (ospf_config.yml) for OSPF on Cisco devices.
- name: Configure OSPF Routing
hosts: cisco_switch
gather_facts: no
tasks:
- name: Configure OSPF
cisco.ios.ios_config:
lines:
- router ospf 1
- network 192.168.1.0 0.0.0.255 area 0
save_when: changed
Run:
ansible-playbook ospf_config.yml
Create a playbook (bgp_config.yml) for BGP on Juniper devices.
- name: Configure BGP on Juniper
hosts: juniper_router
gather_facts: no
tasks:
- name: Configure BGP
juniper.junos.junos_config:
lines:
- set protocols bgp group EXTERNAL neighbor 192.168.2.1 peer-as 65000
- set protocols bgp group EXTERNAL neighbor 192.168.2.1 export EXPORT_POLICY
save_when: changed
Run:
ansible-playbook bgp_config.yml
Create a playbook (backup_config.yml) to backup configurations before changes.
- name: Backup Cisco Config
hosts: cisco_switch
tasks:
- name: Save Running Config
cisco.ios.ios_command:
commands: show running-config
register: config_output
- name: Save Config to Local File
copy:
content: "{{ config_output.stdout[0] }}"
dest: "backups/cisco_running_config_{{ ansible_date_time.date }}.txt"
Run:
ansible-playbook backup_config.yml
This project provides a fully automated solution for managing Cisco and Juniper network devices using Ansible, ensuring consistency, security, and reliability.