Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Troubleshooting Ansible Connection Errors When Managing Devices Running Junos OS

 

The following sections outline connection errors that you might encounter when using Ansible to manage devices running Junos OS. These sections also present potential causes and solutions for each error.

Troubleshooting Failed or Invalid Connection Errors

Problem:

Description:

During execution of an Ansible module on a device running Junos OS, the Ansible control machine generates an error about an unknown command or a failed or invalid SSH connection. For example:

or

or

Cause

These errors can arise when the module or playbook is not run locally. When you execute modules through Ansible, normally the control machine sends the module to the managed node, where it is executed and then removed. Ansible normally requires Python on the managed nodes, but it is not required when managing devices running Junos OS. When using Ansible to manage devices running Junos OS, you must run all modules locally on the control machine. If Ansible tries to execute a module directly on the device running Junos OS, it generates an error.

Solution

To direct the Ansible control machine to run the modules locally, include connection: local in the Ansible playbook, or include the --connection=local command-line argument when executing individual modules. For example:

Troubleshooting Unknown Host Errors

Problem:

Description:

During execution of a Juniper.junos module, the Ansible control machine generates a ConnectUnknownHostError error.

Cause

The host is not defined in the Ansible inventory file.

When executing an Ansible module either directly or from a playbook, any host referenced in the module arguments or the playbook must be defined in the Ansible inventory file. The default location for the inventory file is /etc/ansible/hosts.

Note

The Ansible core modules for Junos OS might generate an “unable to open shell” error for this and other reasons. For more information, see https://docs.ansible.com/ansible/latest/network_debug_troubleshooting.html#unable-to-open-shell.

Solution

Update the Ansible inventory file to include the missing host.

For information about the Ansible inventory file, see Understanding the Ansible Inventory File When Managing Devices Running Junos OS as well as the official Ansible documentation at https://www.ansible.com/.

Troubleshooting Refused Connection Errors

Problem:

Description:

During execution of a Juniper.junos module on a device running Junos OS, the Ansible control machine generates an error that the connection is refused. For example:

Cause

The most likely cause for a refused connection error is that NETCONF over SSH is not enabled on the device running Junos OS.

To quickly test whether NETCONF is enabled, verify that the user account executing the Ansible module can successfully start a NETCONF session with the device.

If the user can successfully establish a NETCONF session with the device on either the default NETCONF port (830) or a port that is specifically configured for NETCONF on your device, then NETCONF is enabled. Otherwise, you must enable NETCONF over SSH on the device.

Note

The Ansible core modules for Junos OS might generate an “unable to open shell” error for this and other reasons. For more information, see https://docs.ansible.com/ansible/latest/network_debug_troubleshooting.html#unable-to-open-shell.

Solution

Enable NETCONF on the device running Junos OS.