ansible/docsite/latest/rst/playbooks_environment.rst

46 lines
1.3 KiB
ReStructuredText
Raw Normal View History

2013-02-23 20:34:29 +01:00
Setting the Environment (and Working With Proxies)
==================================================
2013-02-23 20:34:29 +01:00
.. versionadded:: 1.1
2013-02-23 20:34:29 +01:00
It is quite possible that you may need to get package updates through a proxy, or even get some package
updates through a proxy and access other packages not through a proxy. Ansible makes it easy for you
to configure your environment by using the 'environment' keyword. Here is an example::
2013-02-23 21:17:50 +01:00
- hosts: all
remote_user: root
2013-02-23 20:34:29 +01:00
2013-02-23 21:17:50 +01:00
tasks:
2013-02-23 20:34:29 +01:00
2013-02-23 21:17:50 +01:00
- apt: name=cobbler state=installed
environment:
http_proxy: http://proxy.example.com:8080
2013-02-23 20:34:29 +01:00
The environment can also be stored in a variable, and accessed like so::
2013-02-23 21:17:50 +01:00
- hosts: all
remote_user: root
2013-02-23 20:34:29 +01:00
2013-02-23 21:17:50 +01:00
# here we make a variable named "env" that is a dictionary
vars:
proxy_env:
http_proxy: http://proxy.example.com:8080
2013-02-23 20:34:29 +01:00
2013-02-23 21:17:50 +01:00
tasks:
2013-02-23 21:17:50 +01:00
- apt: name=cobbler state=installed
environment: "{{ proxy_env }}"
2013-02-23 20:34:29 +01:00
2013-02-23 21:17:50 +01: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 20:34:29 +01:00
---
2013-02-23 21:17:50 +01:00
# file: group_vars/boston
ntp_server: ntp.bos.example.com
backup: bak.bos.example.com
proxy_env:
http_proxy: http://proxy.bos.example.com:8080
https_proxy: http://proxy.bos.example.com:8080
2013-02-23 20:34:29 +01:00