how to unset http_proxy in ansible playbook

不打扰是莪最后的温柔 提交于 2019-12-23 13:27:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!