在Ansible中使用curl和环境变量

时间:2017-01-11 09:55:19

标签: ansible ansible-playbook

我需要下载deb包,我用:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.1-amd64.deb

我调查了http://docs.ansible.com/ansible/uri_module.html,但不确定如何将其整合。

我也设置了代理。我怎么能在Ansible中这样做?

我现在正在使用

- name: Download the 5.1.1 version of filebeat
  get_url:
      url: https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.1-amd64.deb
      dest: /home/ubuntu
  environment:
    http_proxy: http://{{ squid_proxy }}:{{ squid_port }}
    https_proxy: https://{{ squid_proxy }}:{{ squid_port }}
  validate_certs: no

1 个答案:

答案 0 :(得分:2)

您应该使用get_url module

- get_url:
    url: https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.1-amd64.deb
    dest: /path/to/destination

它使用http_proxyhttps_proxy环境变量中定义的代理。如果没有为当前用户定义一个(并且它必须在非交互式会话中读取的rc文件中),则可以添加到任务中:

- get_url:
    url: https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.1-amd64.deb
    dest: /path/to/destination
    validate_certs: false  # this might be required for HTTPS proxies with certificates not trusted by the client
  environment:
    https_proxy: https://my.proxy:8080

如果HTTPS代理的下载机器不信任证书,您可能需要将validate_certs: false添加到get_url个参数中。