Automatisation network with Ansible : guide complet for ingénieurs
Guide complet automatisation network with Ansible 2026 : installation, inventaire, playbooks, modules vendors (cisco.ios, cisco.nxos, arista.eos, junipernetworks.junos, fortinet.fortios), AWX/Tower, intégration NetBox. Standard de facto for 85% of équipes NetEng.
Forquoi Ansible for le network
- Agent-less : uses SSH / NETCONF / API REST
- YAML lisible par non-programmeurs
- Idempotent : run multiple = même résultat
- Modules authentic maintenus par vendors
- Large communauté (200 000+ playbooks Galaxy)
- Free (open source)
Installation
- pip install ansible
- ansible-galaxy collection install cisco.ios cisco.nxos arista.eos junipernetworks.juour fortinet.fortios
- Vérification : ansible --version
Inventaire (inventory.yml)
- all:
- children:
- access_switches:
- hosts:
- sw-paris-01:
- ansible_host: 10.0.0.11
- ansible_network_os: cisco.ios.ios
- ansible_user: admin
- ansible_password: "{{ vault_password }}"
- core_switches:
- hosts:
- core-01: ...
Playbook simple : backup configs
- - name: Backup running-config
- hosts: all
- gather_facts: false
- tasks:
- - name: Get running-config
- cisco.ios.ios_command:
- commands: show running-config
- register: config
- - name: Save to file
- copy:
- content: "{{ config.stdout[0] }}"
- dest: "./backups/{{ inventory_hostname }}.cfg"
Playbook : VLAN sur 100 switchs
- - name: Create VLAN 10 DATA on access switches
- hosts: access_switches
- tasks:
- - cisco.ios.ios_vlans:
- config:
- - vlan_id: 10
- name: DATA
- state: active
- state: merged
Modules clés vendors
- cisco.ios : IOS/IOS-XE
- cisco.nxos : NX-OS
- cisco.meraki : Meraki Dashboard API
- cisco.aci : ACI
- arista.eos : Arista
- junipernetworks.juour : Juour (NETCONF)
- fortinet.fortios : FortiGate/FortiSwitch
- paloaltonetworks.paour : Palo Alto
- community.network : multi-vendor basics
Variables and templates Jinja2
- vars/vlans.yml : dict VLAN to déployer
- Templates : génération config from data
- Utilisation : plus maintenable que hardcode
Ansible Vault
Chiffrement passwords dans Git :
- ansible-vault encrypt vars/secrets.yml
- Utilisation : ansible-playbook site.yml --ask-vault-pass
- Intégration CI/CD : GitLab CI variables secrets
AWX / Ansible Tower
- Interface web for playbooks
- RBAC : teams, projects
- Scheduling : exécutions planifiées
- Inventory sync depuis NetBox
- AWX open source, Tower commercial RedHat
Intégration NetBox
- ansible-inventory --list -i netbox.yml : dynamic inventory depuis NetBox
- NetBox = source of truth, Ansible = execution engine
- Workflow : modifier NetBox → auto-push config via Ansible
CI/CD network (GitLab)
- 1. Engineer modifie YAML dans Git
- 2. GitLab CI : ansible-lint + syntax check
- 3. Staging deploy (test switchs)
- 4. Manual approve
- 5. Prod deploy
- 6. Rollback si failure
Best practices
- Idempotence toujours : test multiple runs
- check_mode (--check) : dry-run
- tag tasks for exécution sélective
- Usesr collections vs modules directs (plus maintenu)
- Tests : molecule framework
Limitations
- Pas de state file (vs Terraform)
- Gestion état complexe
- Lenteur sur grosits inventories (parallélisation limitée)
- Solution : Nornir (Python framework) for >500 devices
Commander chez OPTINOC
Form factorion Ansible network + déploiement AWX/Tower + NetBox. CI/CD GitLab. Devis sous 48h.
