ansible-role-nginx
ansible-role-nginx copied to clipboard
Incorrect role name in sample playbooks
Describe the bug
When using the role name provided in sample playbooks, running ansible-playbook
fails because the role is not found.
jacob@pop-os:~/work/vasi-infrastructure$ ansible-playbook -i inventory.ini playbooks/setup-backend-server.yml
PLAY [my first play] **********************************************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [redacted]
TASK [Ping my hosts] **********************************************************************************************************************************************************************************************
ok: [redacted]
TASK [Print message] **********************************************************************************************************************************************************************************************
ok: [redacted] => {
"msg": "Hello world"
}
TASK [Install Nginx] **********************************************************************************************************************************************************************************************
ERROR! the role 'ansible-role-nginx' was not found in /home/jacob/work/vasi-infrastructure/playbooks/roles:/home/jacob/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/jacob/work/vasi-infrastructure/playbooks
The error appears to be in '/home/jacob/work/vasi-infrastructure/playbooks/setup-backend-server.yml': line 13, column 15, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
ansible.builtin.include_role:
name: ansible-role-nginx
^ here
To reproduce
Steps to reproduce the behavior:
- Install role from Ansible Galaxy, fresh install of ansible core.
- Install collections via
requirements.yml
file.
- Install collections via
- Run sample playbook
- Name: my first play
hosts: backend
tasks:
- name: Ping my hosts
ansible.builtin.ping:
- name: Print message
ansible.builtin.debug:
msg: Hello world
- name: Install Nginx
ansible.builtin.include_role:
name: ansible-role-nginx
vars:
nginx_branch: stable
- See error
Expected behavior
I was able to install nginx using the role name nginxinc.nginx
instead. Verified that this is what Ansible expected by manually checking my ~/.ansible/roles
directory.
Your environment
- Version of the Ansible NGINX role or specific commit: 0.24.1
- Version of Ansible: 9.2.0
- Version of Jinja2 (if you are using any templating capability)
- Target deployment platform: Ubuntu 23.10
Thanks for opening an issue @jaketothepast! This one is tricky since while I can see why it could be a bug, it's also a "feature" 😂
The tl;dr is that the sample playbooks are also the playbooks used during the Molecule CI/CD pipeline. During local testing, using nginxinc.nginx
as the role name can cause some issues where depending on your local Ansible settings, the role might get cached and thus new changes will not get properly tested. At the same time, if you were to pull this role from git instead of Ansible Galaxy, you would also need to use ansible-role-nginx
as the role name instead of nginxinc.nginx
. Yet if you download the role from Ansible Galaxy, you will need to use nginxinc.nginx
as the role name, like you correctly identified.
I don't know that there's a way to appropriately fix this in the code, but at minimum I think I can add a note to the README and sample playbooks advising against using one role name or the other.