cloudalchemy / ansible-node-exporter

Provision basic metrics exporter for prometheus monitoring tool
MIT License
501 stars 270 forks source link

Problem downloading sha256sum.txt from github #143

Closed sysbot closed 4 years ago

sysbot commented 4 years ago

What happened? When running the ansible-node-exporter, upon running this task:

    - name: Get checksum list from github
      set_fact:
        _checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt', wantlist=True) | list }}"
      run_once: true

I get the following issue.

[19:01:16] cloudalchemy.node-exporter : Get checksum list from github | host | FAILED | 1742ms {

It seemed that the results return is a 302, which the url did not follow. The option to follow seemed to be added in Ansible Devel. Switching to use uri worked.

Did you expect to see some different?

Expect this to succeed.

How to reproduce it (as minimally and precisely as possible): Attempt to run/use the role.

Environment Ubuntu 18.04

https://github.com/cloudalchemy/ansible-node-exporter/releases/tag/0.19.0
root@c86f70a56fc7:/work# ansible --version
ansible 2.7.1
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.9 (default, Nov  7 2019, 10:44:02) [GCC 8.3.0]
https://github.com/cloudalchemy/ansible-node-exporter/blob/master/tasks/preflight.yml#L78
[19:01:16] cloudalchemy.node-exporter : Get checksum list from github | host | FAILED | 1742ms
{
  - msg: An unhandled exception occurred while running the lookup plugin 'url'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Received HTTP error for https://github.com/prometheus/node_exporter/releases/download/v0.18.1/sha256sums.txt : HTTP Error 400: Bad Request

Anything else we need to know?: Work around at the moment is to patch the task with

    - name: Download checksum list from github
      uri:
        url: "{{ 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt' }}"
        method: GET
        return_content: true
        status_code: 200
        body_format: json
      register: _raw_checksum
      until: _raw_checksum.status == 200
      retries: 5
      run_once: true

    - name: "Get checksum list from github results"
      set_fact:
        _checksums: "{{ _raw_checksum.content.split('\n') }}"
      run_once: true
paulfantom commented 4 years ago

I cannot reproduce it. Could you check if adding retries to set_fact task solves it?

sysbot commented 4 years ago

Thanks for verifying. I found the issue. This is related to urllib automatically pick up netrc in [this][1]. When ~/.netrc exist, running NETRC= ansible-playbook ... will fix the issue.

[1] https://github.com/ansible/ansible/issues/27293