2013-02-23 19:34:29 +00:00
|
|
|
Setting the Environment (and Working With Proxies)
|
2013-09-29 20:47:34 +00:00
|
|
|
==================================================
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2013-08-23 16:33:57 +00:00
|
|
|
.. versionadded:: 1.1
|
2013-02-23 19:34:29 +00:00
|
|
|
|
|
|
|
It is quite possible that you may need to get package updates through a proxy, or even get some package
|
2013-10-05 17:50:53 +00:00
|
|
|
updates through a proxy and access other packages not through a proxy. Or maybe a script you might wish to
|
|
|
|
call may also need certain environment variables set to run properly.
|
2013-10-03 02:02:11 +00:00
|
|
|
|
|
|
|
Ansible makes it easy for you to configure your environment by using the 'environment' keyword. Here is an example::
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2013-02-23 20:17:50 +00:00
|
|
|
- hosts: all
|
2013-09-07 21:19:23 +00:00
|
|
|
remote_user: root
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2013-02-23 20:17:50 +00:00
|
|
|
tasks:
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2013-02-23 20:17:50 +00:00
|
|
|
- apt: name=cobbler state=installed
|
|
|
|
environment:
|
|
|
|
http_proxy: http://proxy.example.com:8080
|
2013-02-23 19:34:29 +00:00
|
|
|
|
|
|
|
The environment can also be stored in a variable, and accessed like so::
|
|
|
|
|
2013-02-23 20:17:50 +00:00
|
|
|
- hosts: all
|
2013-09-07 21:19:23 +00:00
|
|
|
remote_user: root
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2014-04-11 15:48:51 +00:00
|
|
|
# here we make a variable named "proxy_env" that is a dictionary
|
2013-02-23 20:17:50 +00:00
|
|
|
vars:
|
|
|
|
proxy_env:
|
2013-02-27 23:39:08 +00:00
|
|
|
http_proxy: http://proxy.example.com:8080
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2013-02-23 20:17:50 +00:00
|
|
|
tasks:
|
2013-02-23 21:47:47 +00:00
|
|
|
|
2013-02-23 20:17:50 +00:00
|
|
|
- apt: name=cobbler state=installed
|
2015-12-11 14:32:19 +00:00
|
|
|
environment: "{{proxy_env}}"
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2015-10-22 11:07:54 +00:00
|
|
|
You can also use it at a playbook level::
|
|
|
|
|
|
|
|
- hosts: testhost
|
|
|
|
|
|
|
|
roles:
|
|
|
|
- php
|
|
|
|
- nginx
|
|
|
|
|
|
|
|
environment:
|
|
|
|
http_proxy: http://proxy.example.com:8080
|
|
|
|
|
2013-02-23 20:17:50 +00:00
|
|
|
While just proxy settings were shown above, any number of settings can be supplied. The most logical place
|
|
|
|
to define an environment hash might be a group_vars file, like so::
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2013-05-31 08:54:13 +00:00
|
|
|
---
|
2013-02-23 20:17:50 +00:00
|
|
|
# file: group_vars/boston
|
|
|
|
|
|
|
|
ntp_server: ntp.bos.example.com
|
|
|
|
backup: bak.bos.example.com
|
|
|
|
proxy_env:
|
2013-02-27 23:39:08 +00:00
|
|
|
http_proxy: http://proxy.bos.example.com:8080
|
|
|
|
https_proxy: http://proxy.bos.example.com:8080
|
2013-02-23 19:34:29 +00:00
|
|
|
|
2016-07-06 15:18:20 +00:00
|
|
|
.. note::
|
|
|
|
``environment:`` is not currently supported for Windows targets
|
|
|
|
|
2013-10-05 16:31:16 +00:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:doc:`playbooks`
|
|
|
|
An introduction to playbooks
|
|
|
|
`User Mailing List <http://groups.google.com/group/ansible-devel>`_
|
|
|
|
Have a question? Stop by the google group!
|
|
|
|
`irc.freenode.net <http://irc.freenode.net>`_
|
|
|
|
#ansible IRC chat channel
|
|
|
|
|
|
|
|
|