How to pass 'become' to 'include_*' in ansible2.5

Hi all, apparently attributes on include tasks are not propagated to the tasks anymore in 2.5

For some reasons i need dynamic includes.

  1. How would I pass become` to `include_role

The usecase: When I develop a role, it is sometimes based on dynamic facts.

In my role I often use the following pattern:

`

tasks/main.yml

  • include_tasks: preparation.yml

  • include_tasks: configuration.yml
    become: True

  • include_tasks: finish.yml
    become: True

`

As all of the tasks in configuration.yml require become And I am trying to avoid redundancy. On the other Hand I would not like people to have to include the role with a global become statement.

It's explained in the porting guide
https://docs.ansible.com/ansible/2.5/porting_guides/porting_guide_2.5.html#dynamic-includes-and-attribute-inheritance

Hi Kai, thank you i was not aware of that. it looks like an overhead, though (I would either have to introduce blocks in all my includes or type in ‘become’ for 10 times). I just don’t see any advantages in this separation, but well, this is probably OT.

Thanks,
Ilya

you should also be able to :

- block:
     - include_tasks ...
  become: yes

We ARE planning to add a 'bequeath' option to includes to allow
directed keyword inheritance, but it is not ready yet.

Wrapping an include in a block to get that behavior is not functional in 2.5.0/2.5.1, but has been fixed for the 2.5.2 release.

Thanks @Brian, this is good to know

Thanks @Matt - I will take that into account :slight_smile: