Foreman Ansible, Choose the order of launch roles

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

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?

1 Like

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:

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

I opened a new issue (RFE) for this:
https://projects.theforeman.org/issues/27273

1 Like

Although this already solves a lot of problems due to inheritance re-ordering, I also think there should be a possibility to re-order roles within a group/host. For instance, I have a role to set-up my network and another which is based on those facts within a single hostgroup. With the above mentioned solution I’d need to have multiple hostgroups set-up with inheritance to get that to work which seems a tad much and would add confusion for my admins.

My suggestion adds on top of your proposals (because they make sense):
I’d have an extra button up/down when selecting a selectable role on the right hand side. This way the order of the array can be adjusted. As it would only be able to affect the “selectable”/“non-inherited” roles, it would still render the proposal valid :slight_smile:

Hi any news on that particular feature? It will be really useful !

Hi, I have a Host Group with 3 roles and they need to be run in a specific order, what do you mean by meta-role?

Could you give me an example of how to define something that would run roles A,B and C always in that order?

Thank you!

Hi,
you could specify a role as a dependency for another. Ansible docs describe it probably better than I would.

Ok, thank you. Thought there was a mention of doing it with HostGroups and also wasn’t sure role dependency would work with the way the roles are setup in Foreman.

I guess I need to import all roles into Foreman, but only assign top role to the HostGroup.

Isn’t this already possible with the recent foreman_ansible version? The roles can be dragged and keeps the order when we render the playbook right?

1 Like

Yes, it should be possible with the current version.

Current version allowing this would be?

I have Foreman v2.4 and Katello 4.0 and cannot drag and drop the Ansible roles in the UI

It seems the RM issue is not properly updated, but the addition was tracked under Feature #27273: Enable to choose the launch order for Ansible roles - Ansible - Foreman

I think the first version that contained it is foreman_ansible 6.3.0 which was released for Foreman 2.5. Time to upgrade :slight_smile:

Great thank you, will try it out on a 2.5 server!

1 Like