forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of working with the environment
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
|
||
# 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 | ||
|
||
# here we make a variable named "env" that is a dictionary | ||
|
||
vars: | ||
env: | ||
HI: test2 | ||
http_proxy=http://proxy.example.com:8080 | ||
user: root | ||
|
||
tasks: | ||
|
||
# here we just define the dictionary directly and use it | ||
|
||
- shell: echo $HI | ||
environment: | ||
HI: test1 | ||
|
||
# here we are using the $env variable above | ||
|
||
- shell: echo $HI | ||
environment: $env | ||
|
||
|