Troubleshoot Ansible Authentication Errors When Managing Junos Devices
The following sections outline authentication errors that you might encounter when using Ansible to manage devices running Junos OS and devices running Junos OS Evolved. These sections also present potential causes and solutions for each error.
Troubleshoot Authentication Errors
Problem
Description
During execution of a juniper.device module or a
junipernetworks.junos module in the
juniper.device collection, the Ansible control node
generates a ConnectAuthError error or an
AuthenticationException error for failed
authentication. For example:
"msg": "Unable to make a PyEZ connection: ConnectAuthError(dc1a.example.net)"
or
"msg": "AuthenticationException('Authentication failed.')"Cause
The Junos device might fail to authenticate the user for the following reasons:
-
The user does not have an account on the Junos device.
-
The user has an account with a text-based password configured on the Junos device, but the wrong password or no password is supplied for the user when executing the module.
-
The user has an account on the Junos device with SSH keys configured, but the SSH keys are inaccessible on either the device or the control node.
Solution
Ensure that the user executing the modules has a Junos OS login account on all target Junos devices. The account must have an SSH public/private keypair or text-based password configured. If the account uses SSH keys, verify that the user can access the keys.
Troubleshoot Attribute conn_type Errors
Problem
Description
During execution of a juniper.device module, the Ansible
control node generates the following error:
AttributeError: 'JuniperJunosModule' object has no attribute 'conn_type'
Cause
Whereas the older, deprecated Juniper.junos modules supported
using a provider dictionary to define connection and
authentication parameters, the juniper.device modules do not
support using a provider dictionary. If you reference a
provider dictionary, the modules generate the
aforementioned error.
Solution
For the juniper.device modules (excluding
juniper.device.junos_* modules), if you supply connection
and authentication parameters in the playbook’s play, you must define the
parameters in the location appropriate for the Ansible connection.
-
For persistent connections (
connection: juniper.device.pyez), define the parameters under thevars:section. -
For local connections (
connection: local), define the parameters either under thevars:section or as top-level module arguments.
The following playbook uses a persistent connection and defines the
authentication parameter in the playbook's vars section.
---
- name: Get device facts
hosts: dc1
connection: juniper.device.pyez
gather_facts: no
vars_prompt:
- name: "DEVICE_PASSWORD"
prompt: "Device password"
private: yes
vars:
passwd: "{{ DEVICE_PASSWORD }}"
tasks:
- name: Get device facts
juniper.device.facts:
savedir: "{{ playbook_dir }}"
The following playbook uses a local connection and defines the authentication parameter as a module argument.
---
- name: Get device facts
hosts: dc1
connection: local
gather_facts: no
vars_prompt:
- name: "DEVICE_PASSWORD"
prompt: "Device password"
private: yes
tasks:
- name: Get device facts
juniper.device.facts:
passwd: "{{ DEVICE_PASSWORD }}"
savedir: "{{ playbook_dir }}"