fix: avoid hitting api rate limit in lookups

Signed-off-by: gardar <gardar@users.noreply.github.com>
This commit is contained in:
gardar 2023-01-14 01:00:49 +00:00
parent f2737df195
commit 4eace3831e
No known key found for this signature in database
GPG key ID: 00872BAF59D98753
4 changed files with 29 additions and 68 deletions

View file

@ -17,32 +17,17 @@
alertmanager_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[-1] }}"
- name: Discover latest version
ansible.builtin.set_fact:
alertmanager_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/alertmanager/releases/latest', split_lines=False) |
from_json).get('tag_name') | replace('v', '') }}"
run_once: true
until: alertmanager_version is version('0.0.0', '>=')
retries: 10
when:
- alertmanager_version == "latest"
- alertmanager_binary_local_dir | length == 0
block:
- name: Get latest release
ansible.builtin.uri:
url: "https://api.github.com/repos/prometheus/alertmanager/releases/latest"
method: GET
return_content: true
status_code: 200
body_format: json
user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
register: _latest_release
until: _latest_release.status == 200
retries: 5
- name: "Set alertmanager version to {{ _latest_release.json.tag_name[1:] }}"
ansible.builtin.set_fact:
alertmanager_version: "{{ _latest_release.json.tag_name[1:] }}"
alertmanager_checksum_url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/sha256sums.txt"
- name: Get alertmanager binary checksum
delegate_to: localhost
when:
- alertmanager_binary_local_dir | length == 0
block:
@ -51,6 +36,8 @@
__alertmanager_checksums: "{{ lookup('url', 'https://github.com/prometheus/alertmanager/releases/download/v' + alertmanager_version +
'/sha256sums.txt', wantlist=True) | list }}"
run_once: true
until: __alertmanager_checksums is search('linux-' + go_arch + '.tar.gz')
retries: 10
- name: "Get checksum for {{ go_arch }}"
ansible.builtin.set_fact:

View file

@ -27,7 +27,7 @@
url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/\
node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
checksum: "sha256:{{ node_exporter_checksum }}"
checksum: "sha256:{{ __node_exporter_checksum }}"
mode: '0644'
register: _download_binary
until: _download_binary is succeeded

View file

@ -71,43 +71,30 @@
- skip_ansible_lint
- name: Discover latest version
ansible.builtin.set_fact:
node_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/node_exporter/releases/latest', split_lines=False) |
from_json).get('tag_name') | replace('v', '') }}"
run_once: true
until: node_exporter_version is version('0.0.0', '>=')
retries: 10
when:
- node_exporter_version == "latest"
- node_exporter_binary_local_dir | length == 0
delegate_to: localhost
run_once: true
block:
- name: Get latest release
ansible.builtin.uri:
url: "https://api.github.com/repos/prometheus/node_exporter/releases/latest"
method: GET
return_content: true
status_code: 200
body_format: json
user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
register: _latest_release
until: _latest_release.status == 200
retries: 5
- name: "Set node_exporter version to {{ _latest_release.json.tag_name[1:] }}"
ansible.builtin.set_fact:
node_exporter_version: "{{ _latest_release.json.tag_name[1:] }}"
- name: Get node_exporter binary checksum
delegate_to: localhost
when: node_exporter_binary_local_dir | length == 0
block:
- name: Get checksum list from github
ansible.builtin.set_fact:
_checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt',
wantlist=True) | list }}"
__node_exporter_checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version +
'/sha256sums.txt', wantlist=True) | list }}"
run_once: true
until: __node_exporter_checksums is search('linux-' + go_arch + '.tar.gz')
retries: 10
- name: "Get checksum for {{ go_arch }}"
ansible.builtin.set_fact:
node_exporter_checksum: "{{ item.split(' ')[0] }}"
with_items: "{{ _checksums }}"
__node_exporter_checksum: "{{ item.split(' ')[0] }}"
with_items: "{{ __node_exporter_checksums }}"
when:
- "('linux-' + go_arch + '.tar.gz') in item"

View file

@ -73,33 +73,18 @@
- prometheus_alert_rules != []
- name: Discover latest version
ansible.builtin.set_fact:
prometheus_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/prometheus/releases/latest', split_lines=False) |
from_json).get('tag_name') | replace('v', '') }}"
run_once: true
until: prometheus_version is version('0.0.0', '>=')
retries: 10
when:
- prometheus_version == "latest"
- prometheus_binary_local_dir | length == 0
- not prometheus_skip_install
block:
- name: Get latest release
ansible.builtin.uri:
url: "https://api.github.com/repos/prometheus/prometheus/releases/latest"
method: GET
return_content: true
status_code: 200
body_format: json
validate_certs: false
user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
no_log: "{{ not lookup('env', 'ANSIBLE_DEBUG') | bool }}"
register: _latest_release
until: _latest_release.status == 200
retries: 5
- name: "Set prometheus version to {{ _latest_release.json.tag_name[1:] }}"
ansible.builtin.set_fact:
prometheus_version: "{{ _latest_release.json.tag_name[1:] }}"
- name: Get prometheus binary checksum
delegate_to: localhost
when:
- prometheus_binary_local_dir | length == 0
- not prometheus_skip_install
@ -109,6 +94,8 @@
__prometheus_checksums: "{{ lookup('url', 'https://github.com/prometheus/prometheus/releases/download/v' + prometheus_version + '/sha256sums.txt',
wantlist=True) | list }}"
run_once: true
until: __prometheus_checksums is search('linux-' + go_arch + '.tar.gz')
retries: 10
- name: "Get checksum for {{ go_arch }}"
ansible.builtin.set_fact: