# task execution order

**URL:** <https://forum.ansible.com/t/task-execution-order/24183>\
**Category:** Ansible Developer\
**Tags:** rhel, ubuntu\
**Created:** [April 10, 2017, 8:04pm UTC](https://forum.ansible.com/t/task-execution-order/24183 "2017-04-10T20:04:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [April 10, 2017, 8:04pm UTC](https://forum.ansible.com/t/task-execution-order/24183/1 "2017-04-10T20:04:15Z")

</div>

Hi,

I'm facing issue, which how the ansible is running tasks. It's internal  
behaviour of ansible core II donot have answer on users forum.

I'm writing mostly multi os/version enabled roles. See may template role  
on github.I will user it to describe the problem I have.

[https://github.com/hudecof/sensible\_test](https://github.com/hudecof/sensible_test)

managed hosts:  
- debian 7, 8  
- ubuntu 14.04, 16.04  
- centos 6,7  
- rhel 6,7

The main idea is in the tasks/main.yml and in vars/os-XXXXX.yml.  
Inthe VARS file there is a list of tasks file to be included. They vary  
based on the OS, in this case for debian/ubuntu and centos/rhel are the  
same.

The order needs to be keep, the task are dependent in must of the case.

When you run the role, the out put is in logs/full\_run.log  
[https://github.com/hudecof/sensible\_test/blob/master/logs/full\_run.log](https://github.com/hudecof/sensible_test/blob/master/logs/full_run.log)

As you can see, the task execution is  
&nbsp;&nbsp;- task 01 for debian  
&nbsp;&nbsp;- task 02 common  
&nbsp;&nbsp;- task 01 for centos

And there is the problem, I need to run the 'task 01 centos' before the  
'taks 02', the order of the tasks is not the same as specified in  
vars/os-Centos.yml or vars/os-RedHat.yml.

If you run it only against Debian only or CentOs only servers, the order  
is OK.

The problem is, how is ansible handling the tasks includes.

&nbsp;&nbsp;best regards  
&nbsp;&nbsp;&nbsp;&nbsp;Peter Hudec

---

<div class="post-metadata">

**Author:** ![Adam\_Hamsik](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Adam\_Hamsik](https://forum.ansible.com/u/Adam_Hamsik)\
**Post date:** [April 10, 2017, 8:22pm UTC](https://forum.ansible.com/t/task-execution-order/24183/2 "2017-04-10T20:22:22Z")

</div>

Hi,

You are overwriting test\_tasks variable. Variables in ansible re in one global namespace. Therefore debian included version will probably overwrite centos one.

My general suggestion would be to avoid such techniques as it will make role much harder to understand. If role would rather create role per os family. Other way could be to use multile includes.

---

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [April 11, 2017, 7:44am UTC](https://forum.ansible.com/t/task-execution-order/24183/3 "2017-04-11T07:44:02Z")

</div>

Hi,

yes, I tried this approach to remove a lot of skip lines /light blue/  
when per include file 'when' statement.

The previous version was like

- include: task\_01  
&nbsp;&nbsp;when: task\_01.yml in test\_tasks

And the one before the previous was ..

- include: task\_01  
&nbsp;&nbsp;when: {{ ansible\_distribution }} in ('CentOS', 'RedHat')

But for role 'serial console' I need more detailed task chooser, not  
only based on the the distribution, but aslo on distribution version.

[https://galaxy.ansible.com/hudecof/serial-console/](https://galaxy.ansible.com/hudecof/serial-console/)

There is workaround to set 'serial' to 1, but this is really not the way ;(

&nbsp;&nbsp;Peter
