0

I got collection that has structure

   namespace/
── collectionA/
   ├── docs/
   ├── galaxy.yml
   ├── README.md
   └── roles/
        ├── roleA/
        |     └── tasks/
        |           ├──taskA.yml
        |           ├──taskB.yml
        └── roleB/
               └── tasks/
                    ├──taskA.yml
                    ├──taskB.yml

according to using collections if I wan to use that roles all I have to do is include_role with fqdn

- hosts: all
  collections:
    - my_namespace.my_collection

tasks:
  - import_role:
      name: role1

but it seems not working. I still get error:

ERROR! the role 'manage_users' was not found in edaas.post_provisioning:ansible.legacy:/home/jenkins/agent/workspace/Create_Infra/playbooks/roles:/home/cirunner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/jenkins/agent/workspace/Create_Infra/playbooks 12:10:53
12:10:53 The error appears to be in '/home/jenkins/agent/workspace/Create_Infra/playbooks/ansible_main_initial.yml': line 24, column 15, but may 12:10:53 be elsewhere in the file depending on the exact syntax problem. 12:10:53
12:10:53 The offending line appears to be: 12:10:53
12:10:53 - ansible.builtin.import_role: 12:10:53 name: manage_users 12:10:53 ^ here

Collection is installed correctly - checked by ansible-galaxy collection list

Any idea what can be still wrong? Role names are aligned to rules (lowercase and only characters with _ Collection is installed in /home/cirunner/.ansible/collections

ansible [core 2.11.12] config file = None configured module search path = ['/home/cirunner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible ansible collection location = /home/cirunner/.ansible/collections executable location = /usr/local/bin/ansible python version = 3.8.0 (default, Dec 9 2021, 17:53:27) [GCC 8.4.0] jinja version = 3.1.2 libyaml = True

darvark
  • 314
  • 3
  • 15
  • Run an `ansible --version` on your Jenkins box and confirm that the path `/home/cirunner/.ansible/collections` is listed under `ansible collection location` – β.εηοιτ.βε Jun 30 '22 at 10:39
  • It's correct `ansible [core 2.11.12] config file = None configured module search path = ['/home/cirunner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible ansible collection location = /home/cirunner/.ansible/collections executable location = /usr/local/bin/ansible python version = 3.8.0 (default, Dec 9 2021, 17:53:27) [GCC 8.4.0] jinja version = 3.1.2 libyaml = True` – darvark Jun 30 '22 at 10:47
  • 1
    Please don't add this kind of information needed to answer your question and consisting of large pieces of output in a comment: [edit your question](https://stackoverflow.com/posts/72814254/edit). – Zeitounator Jun 30 '22 at 11:59
  • Please make sure the exact path to your collection is `/home/cirunner/.ansible/collections/ansible_collections/my_namespace/my_collection`. The `ansible_collections` inside the path is mandatory as a sub-directory of the configured search path. – Zeitounator Jun 30 '22 at 12:08
  • IT's installed correctly `# /home/cirunner/.ansible/collections/ansible_collections Collection Version ----------------------- ------- namepsace.my_collection 0.0.1` – darvark Jun 30 '22 at 12:10
  • Again, please do not add this kind of information in comments. Edit your question with an output of a command equivalent to `tree`, as you did above but with the entire paths and the real names of your folders that match the ones you pasted in your error message. On a more general level please see [How to create a minimal complete and verifiable example](/help/mcve) – Zeitounator Jun 30 '22 at 12:30
  • sorry I can't publish real structure of files and folders. I guarantee that it's same as in my question, which corresponds to what I've found in official documentation. If you think that it's not enough then specify which information you need, I'll try to prepare them, but without original paths and folder names. There is no typos in paths of names. – darvark Jun 30 '22 at 12:34
  • 1
    if you can't publish your real structure, create your own full minimal and complete example reproducing the problem. This is what is explained in my last link above And regarding your garentee, I totally trust that you **think** everything is installed correctly but I ultimately trust ansible telling you it cannot find your collection/role. Good luck. – Zeitounator Jun 30 '22 at 12:44

2 Answers2

2

I came across this thread, and my issue was I had hyphens in my role name, which is not supported as per the documentation found here.

Changing to underscores in the role name resolved the issue.

Braedon
  • 41
  • 1
  • 5
0

I know this is old but I had a similar issue and it took me hours to find my problem. Maybe the way I figured it out will help someone else.

My problem was an empty collection directory left over from some tests in my project directory <project_dir>/collections/ansible_collection/my_namespace/my_collection directory. ansible-galaxy found the real installed collection containing the role in /usr/share/ansible/collections and reported it as installed and everything fine. But ansible-playbook found the empty directory in my project directory first and interpreted this as the collection location and didn't look further to the actual installed collection in /usr/share/ansible/collections.

So, how I figured it out and how you might be able to figure out your problem:

  1. Explicitly mention the collection in your playbook:
...
    collections:
        - my_namespace.my_collection
  1. Add at least four '-v' arguments when running your playbook: ansible-playbook ... -vvvv
  2. Search for following line and see where your collection was found: Loading collection my_namespace.my_collection from <project_dir>/collections/ansible_collections/my_namespace/my_collection

I hope it helps.

M. Scho.
  • 848
  • 7
  • 10