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)
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:
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
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”.
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
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.