Foreman Ansible, Choose the order of launch roles


#1

Hi,

Does it’s possible to choose the order of lauch Ansible Roles in Foreman (From HostGroups and Hosts) ?
I notoced that the first role wich is played is the last added to HOST/HOSTGROUPS parameters… I would like to be able to change that order

How can i do ?
Does it’s possible ? (My Foreman version is 1.20.2)

Ty


#2

Hi,
the ordering of roles is not yet implemented. The workaround for now is creating a meta-role, that has the roles specified in the correct order.

The main reason is that we are not sure how to tackle inheritance of roles in a flexible but sane way. Currently, we are thinking about having sorted ‘lists’ of roles on each level and adding the roles from the oldest parent first and then moving down the inheritance chain.

Lets say we ‘hostgroup A’, ‘hostgroup B’ and my-host, where host is in ‘hostgroup B’ and ‘hostgroup A’ is a parent of ‘hostgroup B’.

When listing ansible roles for each of them, we would have:

hostgroup B:
role-x
role-y

hostgroup A:
role-x <-- inherited
role-y <-- inherited
role-k
role-c

my-host:
role-x <-- inherited
role-y <-- inherited
role-k <-- inherited
role-c <-- inherited
role-p

my-host would then have in playbook:

roles:
 role-x
 role-y
 role-k 
 role-c
 role-p

What do you think?


#3

Hi,

Thanks for your reply, and for the tips :slight_smile:

In my opinion, if “Host” is in “Hostgroup B”, and “Hostgroup A” is parent of “Hostgroup B” (So “Hostgroup B” is a child of “Hostgroup A”), I got : HostgroupA/HostgroupB/Host

With the inherence of “HostgroupA/HostgroupB/Host” I think that the best approach is to play firstly “Hostgroup A” roles, then “Hostgroup B” roles and finally “Host” roles.

If I use your example, it becomes :

hostgroup A
role-k
role-c

hostgroup B
role-k <–inherited
role-c <–inherited
role-x
role-y

host:
role-k <–inherited
role-c <–inherited
role-x <–inherited
role-y <–inherited
role-p

In my opinion, this inherence is good and can be used in the most common use cases.

Moreover, it could be very useful if we could choose the order of roles execution from Foreman but only for a specific entity. For example, from Hostgroup B, I could be able to change the order of roles “x,y” but no “k,c” because “k,c” are on “Hostgroup A”.

Have a nice day :slight_smile:


#4

Thank you for your reply, I swapped A and B in my example by mistake, it should have been exactly as you suggest…