# pre-tasks doesn't execute before roles...

**URL:** <https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504>\
**Category:** Ansible Project\
**Created:** [March 20, 2020, 3:17pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504 "2020-03-20T15:17:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johanna\_Galarza](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@Johanna\_Galarza](https://forum.ansible.com/u/Johanna_Galarza)\
**Post date:** [March 20, 2020, 3:17pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/1 "2020-03-20T15:17:39Z")

</div>

This is my current setup

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 20, 2020, 3:19pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/2 "2020-03-20T15:19:34Z")

</div>

Playbooks are parsed all at once, and roles which are “static”, are merged into the play at parsing time. They are required to exist before the playbook runs. You could however switch to `include_role`, which loads the role when that “task” is encountered.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [March 20, 2020, 3:24pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/3 "2020-03-20T15:24:39Z")

</div>

> This is my current setup  
> ---  
> - hosts: all  
> pre-tasks:  
> - local\_action:  
> command ansible-galaxy install -r requirements.yml -p . (this install roles roleA, roleB, roleC)  
> roles:  
> - role1  
> - role2
> 
> I have always an error message that it says that role1 doesn't exist... and I cannot see the first command being  
> executed even with a debug message - so I have the feeling it is always executing roles first and then pre-tasks,  
> however, I read that pre-task will be run first.... why does this doesn't apply here?
> 
> Any idea?

No, I think it checks whether the roles are available before running the playbook. So if they are not accessible,  
it terminates before performing any tasks.

I would use separate playbooks for the module installation and the execution of the roles.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Johanna\_Galarza](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@Johanna\_Galarza](https://forum.ansible.com/u/Johanna_Galarza)\
**Post date:** [March 20, 2020, 3:50pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/4 "2020-03-20T15:50:07Z")

</div>

so did that I had this error:  
ERROR! ‘include\_role’ is not a valid attribute for a Play

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 20, 2020, 3:51pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/5 "2020-03-20T15:51:55Z")

</div>

We use a shell wrapper around two playbooks: one that keeps a directory of roles updated, followed by a playbook that then uses those roles.

---

<div class="post-metadata">

**Author:** ![Johanna\_Galarza](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@Johanna\_Galarza](https://forum.ansible.com/u/Johanna_Galarza)\
**Post date:** [March 20, 2020, 3:53pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/6 "2020-03-20T15:53:13Z")

</div>

I did also that one for role installation and another play for the roles and then run them like there

- include\_playbook: requirements.yml
- include\_playbook: project.yml

but same error… roles are not founded ( which of course are not because the requirements.yaml hasn’t done the installation)  
I tried requirement.yamls installing from GitHub but the playbook error was src is cannot be in a play and then with a task same as above but that didn’t install the roles first neither.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 20, 2020, 3:53pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/7 "2020-03-20T15:53:43Z")

</div>

`include_role` is a task, as such it must go under `tasks:`

---

<div class="post-metadata">

**Author:** ![Johanna\_Galarza](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@Johanna\_Galarza](https://forum.ansible.com/u/Johanna_Galarza)\
**Post date:** [March 20, 2020, 4:58pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/8 "2020-03-20T16:58:00Z")

</div>

a shell wrapper?

---

<div class="post-metadata">

**Author:** ![Johanna\_Galarza](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@Johanna\_Galarza](https://forum.ansible.com/u/Johanna_Galarza)\
**Post date:** [March 20, 2020, 5:00pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/9 "2020-03-20T17:00:11Z")

</div>

Got this and it seems that at least the syntax is not complaining anymore but got the following errors… I feel like I am close

fatal: [192.168.1.161]: FAILED! =\> {“msg”: “privilege output closed while waiting for password prompt:\nsu: Sorry\n”}

This is the current setup

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 20, 2020, 5:04pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/10 "2020-03-20T17:04:43Z")

</div>

I’m guessing you want `become: false` on the `local_action`, or some variant on that.

---

<div class="post-metadata">

**Author:** ![Johanna\_Galarza](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@Johanna\_Galarza](https://forum.ansible.com/u/Johanna_Galarza)\
**Post date:** [March 20, 2020, 5:59pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/11 "2020-03-20T17:59:10Z")

</div>

apparently

- local\_action:

become: false  
command ansible-galaxy install -r requirements2.yml -p .

ERROR! unexpected parameter type in action: \<class ‘NoneType’\>

---

<div class="post-metadata">

**Author:** ![vinod93pop](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@vinod93pop](https://forum.ansible.com/u/vinod93pop)\
**Post date:** [March 22, 2020, 4:46pm UTC](https://forum.ansible.com/t/pre-tasks-doesnt-execute-before-roles/32504/12 "2020-03-22T16:46:36Z")

</div>

What is your ansible.cfg looks . Actually it’s stores on your home directory/.ansible. Do a change on cfg that points to roles\_path to this directory as well. This wil help you if you get roles doesn’t exist. Are you running in ansible engine or from ansible tower ?
