# Variable substitution in task meta data

**URL:** <https://forum.ansible.com/t/variable-substitution-in-task-meta-data/17975>\
**Category:** Ansible Developer\
**Created:** [April 14, 2015, 1:48pm UTC](https://forum.ansible.com/t/variable-substitution-in-task-meta-data/17975 "2015-04-14T13:48:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.kusch](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mark.kusch](https://forum.ansible.com/u/mark.kusch)\
**Post date:** [April 14, 2015, 1:48pm UTC](https://forum.ansible.com/t/variable-substitution-in-task-meta-data/17975/1 "2015-04-14T13:48:42Z")

</div>

Hi list,

my goal: A role which allows to configure various aspects how tasks  
should behave, e.g. how to use the become subsystem, especially for  
local\_action tasks.  
Ultimate goal: Configure a few variables in inventory, and have all  
roles behavior configured for that specific infrastructure.

# Assumptions:

- Role foo depends on role foobar (meta/main.yml dependencies:)  
- Role bar depends on role foobar (meta/main.yml ...)  
- Role foobar provides variables to control the become subsystem.  
- Role foo and bar use variables from foobar.

# Role foobar

## defaults/main.yml

&nbsp;&nbsp;&nbsp;&nbsp;foobar\_action\_become\_enable: yes  
&nbsp;&nbsp;&nbsp;&nbsp;#foobar\_action\_become\_user: root  
&nbsp;&nbsp;&nbsp;&nbsp;#foobar\_action\_become\_method: sudo

# Role foo

## tasks/main.yml

&nbsp;&nbsp;&nbsp;&nbsp;- name: Do something that requires sudo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become: "{{ foobar\_action\_become\_enable }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become\_user: "{{ foobar\_action\_become\_user|default(omit) }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become\_method: "{{ foobar\_action\_become\_method|default(omit) }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state=directory  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/usr/local/foo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;owner=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mode=0755

I did something similar with  
[groover.util]([https://github.com/silpion/ansible-util/tree/0.1.0](https://github.com/silpion/ansible-util/tree/0.1.0)) role  
regarding sudo and sudo\_user, which felt to work as intended.

Thing is, ... this doesn't work (anymore, or at least with become).

# Example playbook
