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/70027a23-529b-47b0-b415-4007009fb28d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to