I am trying to use Ansible Collection for example the nginx one.
The directory tree structure looks like this:
├── ansible_collections
│ └── nginxinc
│ └── nginx_core
│ ├── CHANGELOG.md
.......
│ ├── README.md
│ └── roles
│ ├── nginx
│ │ ├── tasks
│ │ │ ├── amplify
│ │ │ ├── config
│ │ │ ├── keys
│ │ │ ├── main.yml
│ │ │ ├── modules
│ │ │ ├── opensource
│ │ │ │ └── install-debian.yml
│ │ │ └── unit
....
├── hosts
└── site.yaml
the site.yaml
file I wrote is:
- name: Demo
hosts: all
connection: local
gather_facts: no
tasks:
- name: test
include_role:
name: nginxinc.nginx_core.nginx
tasks_from: install-debian
I am trying to run the task install-debian
from the role nginx.
I run the playbook:
ansible-playbook -i hosts site.yaml
I get this error:
ERROR! the role 'nginxinc.nginx_core.nginx' was not found.....
I need help on how I should fix the site.yaml
file
2
Answers
If I understand correctly, you should just install the Nginx collection with the following command, as explained here:
It should install it in
~/.ansible/collections/ansible_collections/nginxinc/nginx_core/
. Then create a playbook following these examples and the Ansible docs:Finally run your playbook:
It’ll pick the Debian version for you if your host is Debian.
I regret to say that this is not working for me. this gives the impression that collections_paths is not used.
ansible –version
ansible 2.9.17
ansible-config view
the collections are installed in the /usr/local/ansible_collections folder:
tree -L 2 /usr/local/ansible_collections/nginxinc/
here is the very basic content of the playbook:
cat playbooks/nginx_core.yml
we get the following error message when it is launched:
ansible-playbook playbooks/nginx_core.yml –extra-vars target=myvm.mydomain.org
it doesn’t find the role in the collections, and worse, it doesn’t say that it looked in the collections_path…
But here is a solution that works, but it is very very ugly: add the nginx role of the collection in roles_path!
warning: this is obviously a misuse of the ansible collections!
any help would be appreciated.
Ernest.