💻

Ansible for Network Automation Overview

Feb 1, 2025

Network Chuck Presentation: Ansible for Network Automation

Introduction

  • Focus on Ansible as an IT Automation tool.
  • Applicable for managing and configuring devices (Windows, Linux, routers, switches).
  • Emphasis on Ansible Network Automation, particularly with Cisco routers and switches.

Why Ansible?

  • No programming knowledge required.
  • Popular among network engineers.
  • Can manage multiple devices without knowing Python.

Setting up Ansible for Network Automation

  1. System Preparation

    • Use CentOS as the base system.
    • Update repositories: yum update -y
    • Install EPEL release: yum install epel-release -y
  2. Ansible Installation

    • Install Ansible: yum install ansible -y
    • Configure Ansible by editing the configuration file:
      • Disable host key checking: Find host_key_checking and set it to false.
  3. Managing Cisco Devices

    • Add Cisco routers and switches to the Ansible inventory file.
    • Use Cisco DevNet for free access to routers and switches.
    • Set up an account on developer.cisco.com for access.

Configuring the Inventory File

  • Use variables to connect to routers:
    • Ansible Variables
      • ansible_user=developer
      • ansible_password=developer
      • ansible_connection=network_cli
      • ansible_network_os=ios
      • ansible_port=8181

Testing Configuration

  • Use the ansible command to test connectivity with the ping module.
  • Run commands like show IP interface brief using the ios_command module.

Using Ansible Playbooks

  • Concept of Playbooks

    • Written in YAML format.
    • Automate tasks across multiple devices.
  • Sample Playbook

    • Name: General Config
    • Tasks: Add Banner and Add Loopback Interface
      • Use ios_banner module to modify login banner.
      • Use ios_interface module to add loopback interface.
  • Running the Playbook

    • Execute with ansible-playbook devnet.yml.
    • Demonstrates idempotency: No changes on second run unless configuration differs.

Cleaning Up

  • Remove configurations by setting state to absent in playbook.
  • Verify changes directly on devices.

Advantages of Ansible for Network Automation

  • Ease of use without programming knowledge.
  • Automated configuration management.
  • Supports a wide range of network devices and modules.

Additional Resources

  • Training: CBT Nuggets for CCNP, DevNet, and Ansible course.
  • Suggestion to learn Python for advanced automation.

Conclusion

  • Encouragement to try network automation using Ansible.
  • Explore various modules and automate network tasks efficiently.
  • Feedback invitation from viewers about their tasks and experiences.