I often need to access the default variables of another role. Currently I'm 
doing this via role dependencies, and passing a special variable to skip 
running a roles tasks. E.g.

```

:: my_role/meta/main.yml ::
dependencies:
  - { role: other_role, skip_tasks: True }


:: other_role/tasks/tasks.yml ::
- { include: prepare.yml, tags: ['prepare'], when: skip_tasks is not 
defined or not skip_tasks }

```

This is nice because it accomplishes loading variables from other_role 
(default/main.yml, vars/main.yml) and is a well understood ansible 
convention... although it adds additional variable complexity (skip_tasks) 
and verbosity to the playbook output (all the skipped tasks are reported). 
As an alternative I am thinking about explicitly included the desired vars 
(if they are not already available). E.g.

```

:: my_role/tasks/main.yml ::

- name: gather variables
  include_vars: "'/path/to/other_role/defaults/main.yml"
  when: needed_var_from_other_role is not defined

```

Is this a recommended approach? 

Alternatively I could probably stick all shared variables in a taskless 
common role that's depended upon -- although prefer the naturality of 
keeping the vars in their related role.

Thanks for your insight!

~ Brice

 

-- 
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/adb5acd6-9221-42c5-b0cd-313edafa3e38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to