Ansible 2.4 -> 2.7, include_role
and delegate_to
The final solution
Short description of the problem: In Ansible 2.4 it was possible to write something like that:
- include_role:
name: foo
delegate_to: foo_host
And it worked as expected: role foo
run on host foo_host
. Ansible 2.5 has changed that, and include_role
ignores delegate_to
. (Contrary, import_role
, does respect it). I found few clever tricks to live with this, but Alexey Miasoedov pointed out that there is a much neater way, by using an apply
parameter for include_role
, which supports delegate_to
as well as tags and become
. I have trouble to find words to express gratitude for that, as it saves me tons of efforts to refactor thousands lines of code.
The final solution
- include_role:
name: foo
apply:
delegate_to: foo_host
(note that apply is offset, as it’s an include_role
's parameter).
Compatibility
Unfortunately, there is no way to write a code which works with 2.4 and 2.7 at the same time. apply
does not understood in 2.4, so transition should be done in atomic manner.