dj-wasabi / ansible-telegraf

Installing and configuring Telegraf via Ansible for RedHat/Debian/Ubuntu/Windows/Suse.
MIT License
134 stars 116 forks source link

Proxy not taken into consideration when using 'online' #96

Closed mehyedes closed 5 years ago

mehyedes commented 5 years ago

Describe the bug When using telegraf_agent_package_method=online, the proxy configuration on the remote hosts is not taken into consideration, which causes the package download to fail with a "Connection refused" error. PS: Downloading the package manually on the host using wget works fine.

user@remote-host$ wget https://dl.influxdata.com/telegraf/releases/telegraf-1.10.2-1.x86_64.rpm
--2019-04-10 12:15:45--  https://dl.influxdata.com/telegraf/releases/telegraf-1.10.2-1.x86_64.rpm
Connecting to 192.168.38.10:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 17902995 (17M) [application/x-redhat-package-manager]
Saving to: ‘telegraf-1.10.2-1.x86_64.rpm’
100%[====================================================================================================================>] 17,902,995  53.2MB/s   in 0.3s
2019-04-10 12:15:45 (53.2 MB/s) - ‘telegraf-1.10.2-1.x86_64.rpm’ saved [17902995/17902995]

Not sure if that's not supported by the role, or if I am doing something wrong.

TASK [dj-wasabi.telegraf : RedHat | Download Telegraf package (online)] **************************************************************************************
fatal: [host1]: FAILED! => {"changed": false, "msg": "Failed to connect to dl.influxdata.com at port 443: [Errno 111] Connection refused"}
fatal: [host2]: FAILED! => {"changed": false, "msg": "Failed to connect to dl.influxdata.com at port 443: [Errno 111] Connection refused"}
fatal: [host3]: FAILED! => {"changed": false, "msg": "Failed to connect to dl.influxdata.com at port 443: [Errno 111] Connection refused"}
fatal: [host4]: FAILED! => {"changed": false, "msg": "Failed to connect to dl.influxdata.com at port 443: [Errno 111] Connection refused"}

Installation method/version

Ansible Version

ansible 2.7.8
  config file = None
  configured module search path = ['/Users/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.7.8/libexec/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.2 (default, Feb 12 2019, 08:16:11) [Clang 9.0.0 (clang-900.0.39.2)]

Targetted hosts Concerns the following OS(es):

Expected behavior When proxy configuration is set on the remote hosts, the module should use it to download the telegraf package.

Additional context To make it work, I had to make the following change to the task:

  - name: "RedHat | Download Telegraf package (online)"
    get_url:
      url: https://dl.influxdata.com/telegraf/releases/telegraf-{{ telegraf_agent_version }}-{{ telegraf_agent_version_patch }}.{{ ansible_architecture }}.#
      dest: "{{ telegraf_agent_package }}"
      use_proxy: true
    environment:
      http_proxy: "{{ http_proxy }}"
      https_proxy: "{{ http_proxy }}"
    when:
      - telegraf_agent_package_method == "online"

And set the proxy in my vars files:

http_proxy: http://<PROXY_IP>:<PROXY_PORT>
dj-wasabi commented 5 years ago

HI @midihenry

I created a PR that should fix this issue. Is there a way that you can test it? If documentation is right, only the use_proxy should be set to true. But if this isn't working, then I'll add the environment argument as well.

Thanks!

mehyedes commented 5 years ago

Hi @dj-wasabi , I can confirm that adding use_proxy is not enough. The environment argument must be added as well. That's how I was able to make it work. I am guessing this could be a bug in Ansible itself?

dj-wasabi commented 5 years ago

Hi @midihenry

Thank you for your answer. I added another commit to the PR. Do you see any chance to verify it on your setup? Thanks! 👍