Insights

Ansible network automation: Start with one device

Ansible reads and configures supported network devices. A first playbook checks one VyOS lab device's hostname and software version.

Illustration of bench switch with one live port.
On this page

Ansible automates network tasks such as reading device settings, checking for drift and applying repeatable changes. Your playbook says what to do, your inventory says which devices to target and modules handle the work for each supported platform. To try it, read the hostname and software version from one lab device before you automate a change.

In short:

  • Automate repeatable tasks. Ansible reads, checks and configures supported devices.
  • Start with a read. Run the VyOS facts playbook against one lab device.
  • Check both values. Match the reported hostname and version to the device you meant to reach.

What Ansible can do on your network

A read tells you what a device reports now. A drift check compares its current settings with what you expect. A configuration task changes those settings on a supported device.

Ansible runs network tasks from a control node, the machine where you run Ansible, without installing an Ansible agent on each device. It can connect to network devices over Secure Shell (SSH) or Hypertext Transfer Protocol Secure (HTTPS). The connection and module you use depend on the device platform and the task.

Run one read-only playbook on a lab device

1. Prepare the control node and target. Use a Linux control node with Ansible and compatible ansible.netcommon and vyos.vyos collections already installed. Collections are packages that supply components such as connections and modules. Pick one reachable VyOS lab device and use an account allowed to read its device facts, such as its hostname and software version.

2. Get the playbook and pick the inventory entry. Download first_playbook.yml from the Ansible first-playbook guide. It uses the ansible.netcommon.network_cli connection to reach the device through its command-line interface (CLI) over SSH. The vyos.vyos.vyos_facts module reads device information without changing the configuration.

The playbook targets every host in its inventory, but the command below gives it just one. Replace vyos.example.net with your lab device's hostname and ansible with your username. Keep the trailing comma after the hostname so Ansible treats it as an inline inventory instead of a filename. The -e option identifies the device operating system separately.

3. Run the playbook on Linux from the directory containing the file.

ansible-playbook -i vyos.example.net, -u ansible -k -e ansible_network_os=vyos.vyos.vyos first_playbook.yml

Enter the device password when -k prompts you. Keep the password out of the command, the playbook and any shared files.

Check what came back

Look for the display task to report the hostname and software version you expect from the lab device. A match shows that this playbook could connect and read those facts. If either value is unexpected, check the inline inventory address against the device you meant to reach before you add targets or attempt a write.

If the run fails, try connecting over SSH from the same control node with the same account. Check whether the account can read the device information there. If the manual read works, check the playbook's connection setting and the ansible_network_os value before you retry.

What to check before you add devices or make changes

One inventory can cover several platforms. Group devices by platform where their connection settings differ, and check that each platform's collection supports the exact task you want to run. A working read on one VyOS device doesn't qualify another device, a write task or a wider rollout.

Treat a successful read and a change preview as separate checks. Before relying on check mode, check the write module's documentation for whether it supports a preview and what that preview covers. A preview doesn't prove the change will apply or that you can undo it.

Where doxx.net fits. If you also manage a doxx.net private network, agents can configure that network through an application programming interface (API) with controlled network access. To connect an agent, create a doxx.net account and download the app.

Ask an AI assistant

Share this article

Private Everywhere

Stop giving the internet everything

Keep your browsing, messages, files, and agents private.