task execution order

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

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

As you can see, the task execution is
  - task 01 for debian
  - task 02 common
  - 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.

  best regards
    Peter Hudec

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.

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
  when: task_01.yml in test_tasks

And the one before the previous was ..

- include: task_01
  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/

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

  Peter