Back to Blog
    AutomationNetworkingDevOps

    Network Automation with Ansible: A Practical Guide

    Learn how to automate network device configuration using Ansible playbooks and roles.

    January 2, 20264 min read

    Introduction

    Ansible enables repeatable, version-controlled network automation across major vendors.

    Setup

    bash
    1python -m venv .venv
    2source .venv/bin/activate
    3pip install ansible ansible-pylibssh
    4ansible-galaxy collection install cisco.ios

    Inventory

    yaml
    1# inventory.yml
    2all:
    3 children:
    4 routers:
    5 hosts:
    6 core-rtr-01:
    7 ansible_host: 192.168.1.1
    8 ansible_network_os: cisco.ios.ios
    9 vars:
    10 ansible_connection: ansible.netcommon.network_cli
    11 ansible_user: admin
    12 ansible_ssh_private_key_file: ~/.ssh/network_key

    First Playbook

    yaml
    1- name: Gather Network Facts
    2 hosts: routers
    3 gather_facts: no
    4 tasks:
    5 - name: Gather IOS facts
    6 cisco.ios.ios_facts:
    7 gather_subset:
    8 - all

    Roles and Variables

    • Split configs into roles
    • Use group_vars/host_vars
    • Keep secrets in Ansible Vault

    Run

    bash
    1ansible-playbook -i inventory.yml gather_facts.yml

    Conclusion

    Ansible turns manual CLI changes into auditable automation.

    Ansible
    Cisco IOS
    YAML
    Python

    Written by

    CT

    Corentin Tujague

    Network & Security Engineer

    Passionate about building secure, scalable infrastructure and sharing technical knowledge.