Ansible collection is installed but playbook can't find it.

9,458 views
Skip to first unread message

nishant shah

unread,
Dec 22, 2021, 5:18:13 PM12/22/21
to Ansible Project
Hi,

I am trying to run a simple ansible playbook to create a user in Juniper device. 

I have all the collection junipernetworks.junos installed-

[root@localhost ansible-content]# ansible-galaxy collection list | grep juni
junipernetworks.junos         2.8.0
juniper.device        1.0.1
junipernetworks.junos 2.8.0


But everytime when I try to run the playbook, I get this error-
[root@localhost ansible-content]# ansible-playbook playbook-Create_User.yml
ERROR! 'junipernetworks.junos.junos_user' is not a valid attribute for a Play

The error appears to be in '/home/ansible-content/playbook-Create_User.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Create new user account
  ^ here


Here is my playbook-

[root@localhost ansible-content]# cat playbook-Create_User.yml
---
- name: Create new user account
  hosts: all
  #connection: local
  junipernetworks.junos.junos_user:
    name: ansibleusr
    role: super-user
    state: present


Any help is appriciated
Nish

Felix Fontein

unread,
Dec 22, 2021, 5:22:12 PM12/22/21
to ansible...@googlegroups.com
Hi,

> *[root@localhost ansible-content]# cat playbook-Create_User.yml----
> name: Create new user account hosts: all #connection: local
> junipernetworks.junos.junos_user: name: ansibleusr role:
> super-user state: present*

you need to use the `tasks:` keyword and move the actual task into
there. This is not a valid playbook (with or without collections).

Something like:

- hosts: all
tasks:
- junipernetworks.junos.junos_user:
name: ansibleusr
role: super-user
state: present

Cheers,
Felix

nishant shah

unread,
Dec 22, 2021, 6:28:52 PM12/22/21
to Ansible Project
THanks Felix for quick response. It is still giving an error Method not found-

I updated my playbook-
[root@localhost ansible-content]# cat playbook-Create_User.yml
---
- name: Create new user account
  hosts: all
  tasks:
    - junipernetworks.junos.junos_user:
        name: testusr
        role: super-user
        state: present

It is giving error as-

[root@localhost ansible-content]# ansible-playbook playbook-Create_User.yml
[WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths
that can cause Display to print incorrect line lengths

PLAY [Create new user account] **************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************
ok: [vMX]
ok: [vMX_RE]
ok: [vQFX]

TASK [junipernetworks.junos.junos_user] *****************************************************************************************
fatal: [vMX]: FAILED! => {"changed": false, "module_stderr": "", "module_stdout": "\n{\"failed\": true, \"msg\": \"Method not found\", \"invocation\": {\"module_args\": {\"name\": \"testusr\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n\n{\"failed\": true, \"msg\": \"Method not found\", \"invocation\": {\"module_args\": {\"name\": \"testusr\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
fatal: [vQFX]: FAILED! => {"changed": false, "module_stderr": "", "module_stdout": "\n{\"failed\": true, \"msg\": \"Method not found\", \"invocation\": {\"module_args\": {\"name\": \"testusr\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n\n{\"failed\": true, \"msg\": \"Method not found\", \"invocation\": {\"module_args\": {\"name\": \"testusr\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
fatal: [vMX_RE]: FAILED! => {"changed": false, "module_stderr": "", "module_stdout": "\n{\"failed\": true, \"msg\": \"Method not found\", \"invocation\": {\"module_args\": {\"name\": \"testusr\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n\n{\"failed\": true, \"msg\": \"Method not found\", \"invocation\": {\"module_args\": {\"name\": \"testusr\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Thanks,
Nish

Dick Visser

unread,
Dec 23, 2021, 1:51:39 AM12/23/21
to ansible...@googlegroups.com
What is the output of

ansible --version

?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f75a250a-0e40-464f-9b18-1256ea2d99b0n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Nico Kadel-Garcia

unread,
Dec 23, 2021, 10:32:33 AM12/23/21
to ansible...@googlegroups.com
"ansible --version" no longer reports the version of the "ansible"
plugin. The version of the software no longer has anything to do with
the version of the pypo.org published tarball, it's confusing for
everyone. To check this, use "pip list | grep ansible" or "pip3 list |
grep ansible", depending on your operating system's base version of
python.

ansible < 2.10 actually contains the ansible software
ansible >= 2.10 does not contain the ansible software, the name is
very confusing.

ansible-core >= 2.10 actually contains the critical software but
is published via a pypo.org tarball with a new name.
https://github.com/ansible/ansible/ no longer contains the
tools for the "ansible" tarball at pypi.org
That git repo now contains ansible-core source code
To install ansible commands, use "pip install ansible-core"
Nearly all python requirements need to reset their
requirements.txt as "ansible-core" to get the working ansible python
modules..

This is confusing as hell. I'd love to see the notes or minutes from
whatever committee decided to do this, but I've asked and it is not
available.

ansible > 2.9,< 4.0 not worth the cycles to a lot has been revised.

ansible >= 4 is now purely a collection of ansible galaxy modules.
A modest few of them were formerly in the basic ansible github repo.
https://github.com/ansible-community/antsibull now contains
the tools for building ansible tarballs for pip install
https://github.com/ansible-collections/ now contains the
source for most of these ansible galaxy modules
ansible >= 4 does not contain the ansible software. It requires
"ansible-core", which does.
The claim published with ansible releases that it "includes"
the functional ansible tools is misleading, the correct preposition is
"requires". The working software is actually in the "ansible-core"
python module.
ansible == 4 is huge, more than 400 MBytes of installed modules,
including more than 100 distinct ansible galaxy modules, very few of
which are commonly used and most of which are useful for most ansible
servers.
ansible >= 4 modules all listed among python modules as
"aws_collections" , generally referenced by ansible using the ansible
galaxy tools rather than as standard python modules.
ansible >= 4 modules are available individually with the "ansible
galaxy" galaxy commands, installed individually and updated or
reverted individually.
The "ansible galaxy" command does not install individual
modules in the same location, it publishes them in /usr/share rather
than /usr/lib/python/

This is very confusing. Even Red Hat has not been able to keep their
documentation consistent about this, and they bought ansible.com back
in 2015. And the release announcements claiming that ansible-core is
"included" make it more confusing.

As a user of ansible, someone who's set up several Ansible Tower and
AWX servers myself, I'm game to support update paths. My RPM building
tools for RHEL systems are available over at:

https://github.com/nkadel/ansiblerepo/

Nico Kadel-Garcia
Email: nka...@gmail.com
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwM8-C%2BCYHwNR2J-Dh%3DOp6yyZjT3Mvr8JOWKGtf-TcHyfw%40mail.gmail.com.

nishant shah

unread,
Dec 23, 2021, 12:36:39 PM12/23/21
to Ansible Project
Hi guys,

Thanks for your response. Here is my Ansible version. It is showing the right location for the collection and I can see the collection junipernetworks.junos is there. While running the playbook it gives me a Method not found. So do you think it might be a bug with this version? If it is I am not going to spent too much time on it which I have already spend.


[root@localhost ~]# ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with
Ansible 2.12. Current version: 3.6.8 (default, Aug 12 2021, 07:06:15) [GCC 8.4.1 20200928 (Red Hat
8.4.1-1)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be
 disabled by setting deprecation_warnings=False in ansible.cfg.
ansible [core 2.11.7]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.6.8 (default, Aug 12 2021, 07:06:15) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
  jinja version = 2.10.1
  libyaml = True


nishant shah

unread,
Dec 23, 2021, 1:53:36 PM12/23/21
to Ansible Project
And here is the ansible and ansible-core version-

[root@localhost ~]# pip3 list | grep ansible
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
ansible (4.10.0)
ansible-core (2.11.7)


Rodrigues

unread,
Dec 25, 2021, 7:16:15 AM12/25/21
to Ansible Project
I like to store collections with the playbooks as then it makes sure they wont conflict with others. You can do that with ansible.cfg on your playbook folder.
Then i also called them on my playbook, similar to this
--- 
  - hosts: all
    collections:
      - my_collection
      - my_collection2

Maybe its worth the shot for your issue

Eric Lavarde

unread,
Jan 3, 2022, 4:18:33 AM1/3/22
to Ansible Project
I'm not a specialist in network automation but the docs state "Starting with Ansible 2.5 we recommend using connection: network_cli or connection: netconf". Did you try this? Adding more `-v` (up to 5) should also give you more hints on what might be wrong.

nishant shah

unread,
Jan 3, 2022, 1:07:04 PM1/3/22
to Ansible Project
Thanks for your input. I tried like you said but it is still giving the same error. Can you please point out if I am doing anything wrong. 

- Create ansible.cfg in a working directory where the playbooks are-

[root@ansiblectrl ansible-content]# cat ansible.cfg
[defaults]
collections_paths =  /root/.ansible/collections

- Added collection informations in a playbook

[root@ansiblectrl ansible-content]# cat playbook-CreateUsers.yml
---
- name: create new user account
  hosts: all
  collections:
    - junipernetworks.junos
    - juniper.device

  tasks:
    - junipernetworks.junos.junos_user:
        name: testuser
        role: super-user
        state: present

- After running playbook again, encountered the same error-


TASK [junipernetworks.junos.junos_user] ******************************************************************************************************************************************
task path: /home/ansible-content/playbook-CreateUsers.yml:8
redirecting (type: connection) ansible.builtin.netconf to ansible.netcommon.netconf
redirecting (type: netconf) ansible.builtin.default to ansible.netcommon.default
<192.168.1.34> attempting to start connection
<192.168.1.34> using connection plugin ansible.netcommon.netconf
Found ansible-connection at path /usr/local/bin/ansible-connection
<192.168.1.34> found existing local domain socket, using it!
<192.168.1.34>
<192.168.1.34> local domain socket path is /root/.ansible/pc/d0e6c38e4b
redirecting (type: action) junipernetworks.junos.junos_user to junipernetworks.junos.junos
redirecting (type: action) junipernetworks.junos.junos_user to junipernetworks.junos.junos
<192.168.1.34> ANSIBLE_NETWORK_IMPORT_MODULES: disabled
<192.168.1.34> ANSIBLE_NETWORK_IMPORT_MODULES: module execution time may be extended
<192.168.1.34> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.34> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-81345yk5skhkj `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-81345yk5skhkj/ansible-tmp-1641232750.9852645-81417-187145827529171 `" && echo ansible-tmp-1641232750.9852645-81417-187145827529171="` echo /root/.ansible/tmp/ansible-local-81345yk5skhkj/ansible-tmp-1641232750.9852645-81417-187145827529171 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/junipernetworks/junos/plugins/modules/junos_user.py
<192.168.1.34> PUT /root/.ansible/tmp/ansible-local-81345yk5skhkj/tmpy9i9j30y TO /root/.ansible/tmp/ansible-local-81345yk5skhkj/ansible-tmp-1641232750.9852645-81417-187145827529171/AnsiballZ_junos_user.py
<192.168.1.34> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-81345yk5skhkj/ansible-tmp-1641232750.9852645-81417-187145827529171/ /root/.ansible/tmp/ansible-local-81345yk5skhkj/ansible-tmp-1641232750.9852645-81417-187145827529171/AnsiballZ_junos_user.py && sleep 0'
<192.168.1.34> EXEC /bin/sh -c '/usr/local/bin/python3.7 /root/.ansible/tmp/ansible-local-81345yk5skhkj/ansible-tmp-1641232750.9852645-81417-187145827529171/AnsiballZ_junos_user.py && sleep 0'
<192.168.1.34> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-81345yk5skhkj/ansible-tmp-1641232750.9852645-81417-187145827529171/ > /dev/null 2>&1 && sleep 0'

fatal: [vMX]: FAILED! => {
    "changed": false,
    "module_stderr": "",
    "module_stdout": "\n{\"failed\": true, \"msg\": \"Method not found\", \"exception\": \"  File \\\"/tmp/ansible_junipernetworks.junos.junos_user_payload_rxb51wyz/ansible_junipernetworks.junos.junos_user_payload.zip/ansible_collections/junipernetworks/junos/plugins/module_utils/network/junos/junos.py\\\", line 121, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junipernetworks.junos.junos_user_payload_rxb51wyz/ansible_junipernetworks.junos.junos_user_payload.zip/ansible/module_utils/connection.py\\\", line 200, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"name\": \"testuser\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n\n{\"failed\": true, \"msg\": \"Method not found\", \"exception\": \"  File \\\"/tmp/ansible_junipernetworks.junos.junos_user_payload_rxb51wyz/ansible_junipernetworks.junos.junos_user_payload.zip/ansible_collections/junipernetworks/junos/plugins/module_utils/network/junos/junos.py\\\", line 121, in get_capabilities\\n    capabilities = Connection(module._socket_path).get_capabilities()\\n  File \\\"/tmp/ansible_junipernetworks.junos.junos_user_payload_rxb51wyz/ansible_junipernetworks.junos.junos_user_payload.zip/ansible/module_utils/connection.py\\\", line 200, in __rpc__\\n    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)\\n\", \"invocation\": {\"module_args\": {\"name\": \"testuser\", \"role\": \"super-user\", \"state\": \"present\", \"purge\": false, \"active\": true, \"aggregate\": null, \"full_name\": null, \"encrypted_password\": null, \"sshkey\": null, \"provider\": null}}}\n",

    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP ***********************************************************************************************************************************************************************
vMX                        : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

nishant shah

unread,
Jan 3, 2022, 1:09:41 PM1/3/22
to Ansible Project
Hi,

Yeah, I am using netconf over the SSH. I am able to update configuration on Juniper devices using roles. But somehow the Ansible can't find the collection althought it is installed. I am trying to using collections over roles because collections has more varieties.

Thanks,
Nish

Nico Kadel-Garcia

unread,
Jan 3, 2022, 1:52:42 PM1/3/22
to ansible...@googlegroups.com
On Mon, Jan 3, 2022 at 1:09 PM nishant shah <linkt...@gmail.com> wrote:
>
> Hi,
>
> Yeah, I am using netconf over the SSH. I am able to update configuration on Juniper devices using roles. But somehow the Ansible can't find the collection althought it is installed. I am trying to using collections over roles because collections has more varieties.

Installed *where* ? How did you install it? With the "pip install"
command as the root user?

Nico Kadel-Garcia

nishant shah

unread,
Jan 3, 2022, 2:56:47 PM1/3/22
to Ansible Project
Yes, using pip and ansible-galaxy collection.

[root@localhost ansible-content]# ansible-galaxy collection list | grep juni
junipernetworks.junos         2.8.0
juniper.device        1.0.1
junipernetworks.junos 2.8.0


Eric Lavarde

unread,
Jan 4, 2022, 8:26:44 AM1/4/22
to Ansible Project

Perhaps I was unclear but from the look of it, you don't have an issue finding the collection/module but you have an issue within the module itself. You could try to get some more information using the ANSIBLE_DEBUG environment variable, else I fear you'll have to debug the module.

Hamza Bouabdallah

unread,
Jan 4, 2022, 9:32:31 AM1/4/22
to Ansible Project
aren't you missing the "tasks:" directive ? ^^"
just before your  " junipernetworks.junos.junos_user: "

nishant shah

unread,
Jan 5, 2022, 3:21:17 PM1/5/22
to Ansible Project
I think it is actually finding the right collection but somehow the playbook is not running. Maybe the playbook I have is not right? Do you have a link to a doc to troubleshoot  using the ANSIBLE_DEBUG environment variable?

It can see the ansible-doc for that specific collection which I am trying to use-

[root@ansiblectrl ansible-content]# ansible-doc-2.7 junipernetworks.junos.junos_user
> JUNOS_USER    (/root/.ansible/collections/ansible_collections/junipernetworks/junos/plugins/modules/junos_user.py)

        This module manages locally configured user accounts on remote network devices running the JUNOS operating system.
        It provides a set of arguments for creating, removing and updating locally defined accounts

  * This module is maintained by The Ansible Community
OPTIONS (= is mandatory):

- active
        Specifies whether or not the configuration is active or deactivated
        [Default: True]
        type: bool

- aggregate
        The `aggregate' argument defines a list of users to be configured on the remote device.  The list of users will be
        compared against the current users and only changes will be added or removed from the device configuration.  This
        argument is mutually exclusive with the name argument.
        (Aliases: users, collection)[Default: (null)]
        elements: dict
        suboptions:
          active:
            description:
            - Specifies whether or not the configuration is active or deactivated
            type: bool
          encrypted_password:
            description:
            - The `encrypted_password' argument set already hashed password for the user
              account on the remote system.
            type: str
          full_name:
            description:
            - The `full_name' argument provides the full name of the user account to be created
              on the remote device.  This argument accepts any text string value.
            type: str
          name:
            description:
            - The `name' argument defines the username of the user to be created on the system.  This
              argument must follow appropriate usernaming conventions for the target device
              running JUNOS.  This argument is mutually exclusive with the `aggregate' argument.
            required: true
            type: str
          purge:
            default: false
            description:
            - The `purge' argument instructs the module to consider the users definition
              absolute.  It will remove any previously configured users on the device with
              the exception of the current defined set of ag


Here is my Playbook that I am trying to run-

[root@ansiblectrl ansible-content]# cat playbook-CreateUsers.yml
---
- name: create new user account
  hosts: all

  collections:
    - junipernetworks.junos
    - juniper.device
  tasks:
    - junipernetworks.junos.junos_user:
        name: testuser
        role: super-user
        state: present

nishant shah

unread,
Jan 7, 2022, 7:45:24 PM1/7/22
to Ansible Project
Hey guys, I found the solution-

The main issue was "junipernetworks.junos.junos_user" is created by core Ansible team and not maintained by Juniper team members. Whereas "juniper.device" is created and maintained by Juniper team members which takes API as ansible_connection=juniper.device.pyez . But that won't work on junipernetworks.junos.junos_user.

So the fix is to add following lines in inventory/host file.
ansible_connection=ansible.netcommon.netconf
ansible_network_os=junipernetworks.junos.junos


Thanks to everyone who took the time to help.
Solved :)
Reply all
Reply to author
Forward
0 new messages