I wrote a playbook that uses a set of roles according the suggested structure https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html#role-directory-structure
Now I want to use a Ansible Galaxy dependency for the first time and defined it in requirements.yml
and install it in the playbook itself.
I want to call the role in my subrole task subrole/tasks/main.yml
. As stated in the documentation (https://galaxy.ansible.com/geerlingguy/postgresql) the role needs root access. In a play this is easy and only an added become: true
is working. However in my task I need to use the include_role
module that had this feature once, but it was removed. Now there is another option called apply
that's documentation (https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_role_module.html#parameter-apply) states the same feature: Accepts a hash of task keywords (e.g. tags, become) that will be applied to all tasks within the included role.
But this is not working. The error message clearly states the the root privilege is missing.
- name: use postgresql role
ansible.builtin.include_role:
name: geerlingguy.postgresql
apply:
become: true
What am I doing wrong? Why was the direct way of using become like in a play removed at all? Should tasks be avoided? Questions over questions...
I don't know why it didn't work in the first place. It is working now exactly as written here, very strange.