http://docs.ansible.com/faq.html#how-can-i-set-the-path-or-any-other-environment-variable-for-a-task-or-entire-playbook
i get this. ^^ …but how do i set environment variables for a role? i want it associated with a role and not a playbook.
comment: it seems environment variables are not first-class variables. i just want to use (regular) variables and apply them as environment variables whenever needed (as env vars).
I'm not sure what you are asking, so I'll respond to the 2
interpretations I have.
1) add environment variables to all tasks in a role: use environment:
directive in the role definition, it takes a dictionary from which it
converts keys into environment variables and assigns the their
dictionary values to them.
2) you wan to access existing environment variables, you can do so
through lookup('env', 'varname')
i tried that already. environment
does not work in role definition. I’m on 1.9.2.
`
- hosts:
- localhost
gather_facts: false
environment:
ENVVAR: WORKS
roles:
- role: myrole
environment:
ENVVAR: DOESNOTWORK
`
sorry, you are correct, environment will added to roles in 2.0 (should
work in current devel)