Tutorials · DevOps & Containers
How to Automate Switch and Server Configuration With Ansible
Stop typing the same commands on fifty devices. Describe the desired state once in an Ansible playbook and apply it to every switch, gateway and edge server over SSH.
Before you start
- Ansible on a management host or jump host
- SSH key access to the devices
- A test device or lab
Step by step
Write an inventory
Group devices by role and site.
# inventory.ini [edge] site1-edge ansible_host=10.1.99.20 site2-edge ansible_host=10.2.99.20 [edge:vars] ansible_user=admin
Check connectivity
Ansible connects over SSH with your key.
ansible -i inventory.ini edge -m pingWrite a playbook
Describe the desired state: here, Docker installed and the site stack deployed on every edge server.
# edge.yml - hosts: edge become: true tasks: - name: Docker is installed ansible.builtin.package: { name: docker.io, state: present } - name: Compose files are in place ansible.builtin.copy: { src: files/compose.yaml, dest: /opt/site/compose.yaml } - name: Stack is running ansible.builtin.command: docker compose -f /opt/site/compose.yaml up -d changed_when: false
Dry run first
--check --diff shows what would change without changing anything.
ansible-playbook -i inventory.ini edge.yml --check --diff --limit site1-edgeRoll out in waves
Apply to one site, verify, then the rest.
ansible-playbook -i inventory.ini edge.yml --limit site1-edge ansible-playbook -i inventory.ini edge.yml
Network devices
For switches, use the vendor's Ansible collection or its CLI over SSH with the same inventory and dry-run discipline.
Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.
Pro tips
- Keep playbooks in Git and review them like code.
- Store secrets in Ansible Vault, never in plain text.
FAQ
Frequently asked questions
Ansible or NavCloud?
Use NavCloud for Navijin devices: zero-touch provisioning, templates and firmware at scale. Use Ansible for Linux edge servers and mixed-vendor tasks.
Keep learning
Related guides
Configuration as code with Git
Read more →Zero-touch provisioning with NavCloud
Read more →How to Use SSH Keys Instead of Passwords for Network Devices and Servers
Passwords can be guessed, phished and reused. Create an SSH key pair, install the public key on gateways, edge servers and Linux hosts, then turn password logins off.
Read more →How to Reach Remote Sites Safely With an SSH Jump Host
Do not expose SSH on every device. Put one hardened jump host (bastion) in front of the management network and reach everything else through it.
Read more →How to Open a Device Web Page Through an SSH Tunnel
Reach the web interface of a switch, NVR or container on a remote site without opening a firewall port: forward it through SSH.
Read more →Stuck on a step?
Ask Navijin technical support or an authorised partner for help with your configuration.