6

我只想为特定的 ansible 任务(如get_url模块)设置环境代理,以从 Internet 下载某些应用程序。其他所有任务都应该在没有任何代理的情况下运行。我如何完成这项任务。

4

2 回答 2

7

您可以为每个任务设置一个代理,如下所示:

get_url:
  url=http://remote.host.com/file
  dest=/tmp/file
environment:
  http_proxy: http://proxy.example.com:8080
于 2016-11-10T19:03:35.353 回答
7

您可以为您的游戏定义一个环境变量并设置代理选项get_url

---
- hosts: all

  environment:
    http_proxy: http://127.0.0.1:1234

    # You can also set it over https.
    https_proxy: http://127.0.0.1:1234

- name: Retrieve some repo
  get_url:
    url: https://repos.com/cool.repo
    dest: /etc/yum.repos.d/cool.repo
    use_proxy: yes   

文档use_proxy中:

如果 [use_proxy设置为 ] no,它将不使用代理,即使在目标主机上的环境变量中定义了代理。

因此,您将在上面的示例中做相反的事情。

于 2017-05-17T20:48:01.267 回答