问题
In most ansible example, it is to set environment like setting http_proxy below, see http://docs.ansible.com/playbooks_environment.html
- hosts: all
tasks:
- apt: name=cobbler state=installed
environment:
http_proxy: http://proxy.example.com:8080
In my case, I need this http_proxy
in system shell, while I want to disable this in playbook, how can I achieve this ?
If I work in shell, I can use unset http_proxy
回答1:
You could temporarily disable the proxy for the host(s) or URL you wanted to talk to, e.g.
environment:
no_proxy: 192.168.1.2,www.google.com
回答2:
Your play will do just that: The environment will only be set for that task, and any subsequent task will not have the variable set.
Try for example:
- hosts: all
tasks:
- apt: name=cobbler state=installed
environment:
http_proxy: http://proxy.example.com:8080
- shell: "echo $http_proxy"
The shell task will return: "stdout": ""
来源:https://stackoverflow.com/questions/25545195/how-to-unset-http-proxy-in-ansible-playbook