2013-02-10 19:08:16 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# it is often useful to be able to set the environment for one command and have that environment be totally
|
|
|
|
# different for another. An example is you might use a HTTP proxy for some packages but not for others.
|
|
|
|
#
|
|
|
|
# in Ansible 1.1 and later, you can pass the environment to any module using either a dictionary variable
|
|
|
|
# or a dictionary itself.
|
|
|
|
|
|
|
|
|
|
|
|
- hosts: all
|
2013-02-10 19:20:19 +01:00
|
|
|
user: root
|
2013-02-10 19:08:16 +01:00
|
|
|
|
|
|
|
# here we make a variable named "env" that is a dictionary
|
|
|
|
vars:
|
|
|
|
env:
|
|
|
|
HI: test2
|
2013-05-05 19:33:05 +02:00
|
|
|
http_proxy: http://proxy.example.com:8080
|
2013-02-10 19:08:16 +01:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
# here we just define the dictionary directly and use it
|
2013-05-05 19:33:05 +02:00
|
|
|
# (here $HI is the shell variable as nothing in Ansible will replace it)
|
2013-02-10 19:08:16 +01:00
|
|
|
|
|
|
|
- shell: echo $HI
|
|
|
|
environment:
|
|
|
|
HI: test1
|
|
|
|
|
|
|
|
# here we are using the $env variable above
|
|
|
|
|
|
|
|
- shell: echo $HI
|
2013-05-05 19:33:05 +02:00
|
|
|
environment: env
|
2013-02-10 19:08:16 +01:00
|
|
|
|
|
|
|
|