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

47 views
Skip to first unread message

ProfHase

unread,
Apr 23, 2018, 12:27:37 PM4/23/18
to Ansible Project
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.

Kai Stian Olstad

unread,
Apr 23, 2018, 3:45:50 PM4/23/18
to ansible...@googlegroups.com
On 23.04.2018 18:27, ProfHase wrote:
> 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


--
Kai Stian Olstad

ProfHase

unread,
Apr 24, 2018, 5:31:36 AM4/24/18
to Ansible Project
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

Brian Coca

unread,
Apr 24, 2018, 11:54:30 AM4/24/18
to Ansible Project
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.


--
----------
Brian Coca

Matt Martz

unread,
Apr 24, 2018, 12:01:20 PM4/24/18
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7dRmywFLmCQi0GR90_8v1AxpOZVMR7p%3DPtnfbRiVt3mxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

ProfHase

unread,
Apr 26, 2018, 4:16:32 AM4/26/18
to Ansible Project
Thanks @Brian, this is good to know

Thanks @Matt - I will take that into account :)
Reply all
Reply to author
Forward
0 new messages