Search code examples
ansibleansible-collections

Run ansible playbook from installed collection


I installed my own collection via from a private git repository via

ansible-galaxy collection install <clone URL of the git repository>,<version>

which installed the collection to

~/.ansbile/collections/ansible_collections/<namespace>/<name>

Checking ~/.ansbile/collections/ansible_collections/<namespace>/<name>

According to the documentation https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#using-a-playbook-from-a-collection I should be able to (dry-)run the playbook via

ansible-playbook <namespace>.<name>.<my_playbook> -i <path to my inventory> --check --ask-become-pass

I however get an error

ERROR! the playbook: <namespace>.<name>.<my_playbook> could not be found

Checking

$ ansible-config dump | grep collection
COLLECTIONS_PATHS(default) = ['~/.ansible/collections', '/usr/share/ansible/collections']

and

$ ansible --version
ansible [core 2.13.0]
  config file = None
  configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/conda/envs/ansible/lib/python3.9/site-packages/ansible
  ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/conda/envs/ansible/bin/ansible
  python version = 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:56:21) [GCC 10.3.0]
  jinja version = 3.1.2
  libyaml = True

Specifying the path to the playbook by hand

ansible-playbook ~/.ansible/collections/ansible_collections/<namespace>/<name>/playbooks/files/<my_playbook>.yml -i <path to my inventory> --check --ask-become-pas

also works as expected.

So what am I missing here?


Solution

  • Ok, turns out that the playbook should be in

     ~/.ansible/collections/ansible_collections/<namespace>/<name>/playbooks/<my_playbook>.yml
    

    and not in

     ~/.ansible/collections/ansible_collections/<namespace>/<name>/playbooks/files/<my_playbook>.yml