Troubleshoot Ansible Collection and Module Errors When Managing Junos Devices
The following sections discuss errors that you might encounter when using the
juniper.device Ansible collection to manage devices running Junos OS and
devices running Junos OS Evolved.
Problem
Description
During execution of an Ansible playbook, the control node generates an error that it
could not resolve a juniper.device module or
junipernetworks.junos module or that no action was detected in the
task. For example:
ERROR! couldn't resolve module/action 'juniper.device.facts'. This often indicates a misspelling, missing collection, or incorrect module path.
[ERROR]: couldn't resolve module/action 'junipernetworks.junos.junos_facts'. This often indicates a misspelling, missing collection, or incorrect module path.
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
Cause
The Ansible control node cannot locate the juniper.device collection and
associated modules. Starting in juniper.device Release 2.0.0, the
collection includes the junipernetworks.junos modules in addition to the
original juniper.device modules.
Solution
The juniper.device collection is hosted on the Ansible Galaxy website. In
order to use the modules in the collection, you must install the collection on the Ansible
control node and also reference it in your playbook.
To install the juniper.device collection on the Ansible control node,
execute the ansible-galaxy collection install command, and specify
juniper.device.
user@ansible-cn:~$ ansible-galaxy collection install juniper.device
If you do not install the collection in the default location, you might need to define the path to it in your Ansible setup. For more information about installing collections and specifying the path, see the official Ansible documentation.
To use the modules in the juniper.device collection, reference the fully
qualified collection name when you execute a module. You must also define the appropriate
connection and network OS variables for the module set that you use. You can define the
variables in different locations, for example, in your inventory file, in your host or group
variable files, in your playbook, or as command-line arguments. For more information about
the juniper.device module sets, see Understanding the Ansible for Junos OS Collections and Modules.
The following example playbook references the given inventory file and executes the
juniper.device.facts module.
# Inventory [junos] host1.example.com [junos:vars] ansible_connection=local
---
- name: Get Device Facts
hosts: junos
gather_facts: no
tasks:
- name: Get device facts
juniper.device.facts:
savedir: "{{ playbook_dir }}"
If you are using the junipernetworks.junos modules from the merged
juniper.device collection and your playbook still references the
junipernetworks.junos namespace:
-
In your playbook, update the fully qualified collection name to use
juniper.device. -
In your inventory file, set
ansible_network_ostojuniper.device.junos.
The following playbook references the given inventory file and executes the
juniper.device.junos_facts module.
# Inventory [junos] host2.example.com [junos:vars] ansible_connection=ansible.netcommon.netconf ansible_network_os=juniper.device.junos
---
- name: Get Device Facts
hosts: junos
gather_facts: no
tasks:
- name: Get device facts
juniper.device.junos_facts:
junipernetworks.junos
namespace, you can install both the juniper.device and
junipernetworks.junos collections. However, you still need to update the
Ansible network OS variable in your inventory file.