-1

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...

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
jan
  • 2,741
  • 4
  • 35
  • 56
  • I can add the question when to use import_role over include_role beside the thin details named in documentation. – jan Jan 04 '23 at 11:57
  • 1
    No features were removed from `include_role`. `include` was split into a number of discrete tasks (including `include_role` and `import_role`) so that people had to explicitly say what they wanted instead of a single directive magically behaving differently due to opaque rules, but no functionality was removed in the split. The differences between static imports and dynamic includes are clearly laid out in the documentation: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse.html#re-using-files-and-roles . – flowerysong Jan 04 '23 at 18:56

1 Answers1

0

I don't know why it didn't work in the first place. It is working now exactly as written here, very strange.

jan
  • 2,741
  • 4
  • 35
  • 56