Hello.

It doesn't exactly meet my need, I'd like to be able to write:

# roles/roleA/tasks/main.yml
---
- file: path=/tmp/foo owner="{{ var_rolea|default(omit) }}"




Le lundi 14 septembre 2015 12:27:54 UTC+2, Trond Hindenes a écrit :
>
> In your RoleB role, use a defaults file to handle default variables. That 
> will ensure you always have the var_roleb variable defined.
> http://docs.ansible.com/ansible/playbooks_roles.html#role-default-variables
>
>
> On Sunday, September 13, 2015 at 1:19:32 PM UTC+2, Arnaud Mazin wrote:
>>
>> Hi
>>
>> I'm trying to nest roles using dependencies in order to reuse as much 
>> code as possible and get into trouble when trying to omit some parameters
>>
>> My setup:
>>
>> # roles/roleA/tasks/main.yml
>> ---
>> - debug: msg="var var_rolea is set to {{ var_rolea|default('no idea') }}"
>>
>> # roles/roleB/meta/main.yml
>> dependencies:
>>   - { role: roleA,
>>       var_rolea: "{{ var_roleb }}"
>>     }
>>
>> # playbook
>> # play1, specify value
>> - hosts: localhost
>>   gather_facts: no
>>   roles:
>>     - role: roleB
>>       var_roleb: plop
>>
>> # play2, omit value, let defaults apply
>> - hosts: localhost
>>   gather_facts: no
>>   roles:
>>     - role: roleB
>>
>>
>>
>> I get a « fatal: [localhost] => One or more undefined variables: 
>> 'var_roleb' is undefined » error in this case.
>>
>> I tried several tricks into the roleB/meta/main.yml, such as:
>>
>>    - var_rolea: "{{ var_roleb|default(omit) }}"
>>    - var_rolea: "{{ var_roleb|default(None) }}"
>>    
>> But so far, I haven't found a pretty way to do this.
>>
>> Any Idea?
>>
>> Regards,
>>
>> Arnaud
>>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4f8d5116-cb67-4cc1-8435-fccec1def2e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to