ansibleansible-2.x

Ansible: using "become" with "import_role"


I am using import_role in my playbooks to run roles at specific points throughout my tasks. Some of the imported roles require elevated permissions, so I have been trying to use become: yes with them, with mixed results.

Here is an example of how I'm using import_role:

---
- import_role:
    name: geerlingguy.redis
  become: yes

Tasks within the imported role seem to run without issue, though with some roles that doesn't work either.

One of the consistent areas I run into problems is with the handlers in imported roles, that do not seem to receive the become: yes statement because they throw "Authentication required" errors. I end up having to copy their handlers inside whatever role I'm writing.

I am running Ansible version 2.5.0.

How can I consistently and reliably pass become through to imported roles?


Solution

  • There's a series of bugs in 2.5.0 that are related to inheritance and I think that's what you're hitting here. Unfortunately the fix wasn't found in time for the 2.5.1 release but there should be a resolution for this in the 2.5.2 release.