How to specify ansible pretasks for a role?

Question:

How should one go about defining a pretask for role dependencies.
I currently have an apache role that has a user variable so in my own role in <role>/meta/main.yml I do something like:

The problem at this point is that I still don’t have the user I specify and when the role tries to start apache server under a non existent user, I get an error.

I tried creating a task in <role>/tasks/main.yml like:

But the user gets created only after running the apache task in dependencies (which is to be expected). So, is there a way to create a task that would create a user before running roles in dependencies?

Answer:

As of Ansible 2.2, you can use include_role.
https://docs.ansible.com/ansible/include_role_module.html

Leave a Reply