Skip to content

Commit

Permalink
fix(mysqld_exporter): simplify go architecture variable
Browse files Browse the repository at this point in the history
Signed-off-by: gardar <[email protected]>
  • Loading branch information
gardar committed Jun 20, 2024
1 parent 6d726ea commit e9dcb24
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion roles/mysqld_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mysqld_exporter_version: 0.15.1
mysqld_exporter_binary_local_dir: ""
mysqld_exporter_binary_url: "https://github.com/{{ _mysqld_exporter_repo }}/releases/download/v{{ mysqld_exporter_version }}/\
mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch }}.tar.gz"
mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}.tar.gz"
mysqld_exporter_checksums_url: "https://github.com/{{ _mysqld_exporter_repo }}/releases/download/v{{ mysqld_exporter_version }}/sha256sums.txt"
mysqld_exporter_skip_install: false

Expand Down
3 changes: 2 additions & 1 deletion roles/mysqld_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ argument_specs:
- "This overrides the I(mysqld_exporter_version) parameter"
mysqld_exporter_binary_url:
description: "URL of the mysqld_exporter binaries .tar.gz file"
default: "https://github.com/prometheus/{{ _mysqld_exporter_repo }}/download/v{{ mysqld_exporter_version }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch }}.tar.gz"
default: "https://github.com/prometheus/{{ _mysqld_exporter_repo }}/download/v{{ mysqld_exporter_version }}/\
mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}.tar.gz"
mysqld_exporter_checksums_url:
description: "URL of the mysqld_exporter checksums file"
default: "https://github.com/{{ _mysqld_exporter_repo }}/releases/download/v{{ mysqld_exporter_version }}/sha256sums.txt"
Expand Down
2 changes: 1 addition & 1 deletion roles/mysqld_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ provisioner:
http2: true
mysqld_exporter_basic_auth_users:
randomuser: examplepassword
go_arch: amd64
_mysqld_exporter_go_arch: amd64
mysqld_exporter_version: 0.15.0
14 changes: 5 additions & 9 deletions roles/mysqld_exporter/molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
- name: Download mysqld_exporter binary to local folder
become: false
ansible.builtin.get_url:
url: "https://github.com/prometheus/mysqld_exporter/releases/download/v{{\
\ mysqld_exporter_version }}/mysqld_exporter-{{ mysqld_exporter_version\
\ }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch\
\ }}.tar.gz"
url: "https://github.com/prometheus/mysqld_exporter/releases/download/v{{ mysqld_exporter_version }}/\
mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}.tar.gz"
dest: "/tmp/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}.tar.gz"
mode: 0644
register: _download_binary
until: _download_binary is succeeded
Expand All @@ -21,11 +19,9 @@
- name: Unpack mysqld_exporter binary
become: false
ansible.builtin.unarchive:
src: "/tmp/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch\
\ }}.tar.gz"
src: "/tmp/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch\
\ }}/mysqld_exporter"
creates: "/tmp/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}/mysqld_exporter"
check_mode: false

- name: Link to mysqld_exporter binaries directory
Expand Down
8 changes: 4 additions & 4 deletions roles/mysqld_exporter/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
become: false
ansible.builtin.get_url:
url: "{{ mysqld_exporter_binary_url }}"
dest: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}.tar.gz"
checksum: "sha256:{{ __mysqld_exporter_checksum }}"
mode: '0644'
register: _download_binary
Expand All @@ -40,17 +40,17 @@
- name: Unpack mysqld_exporter binary
become: false
ansible.builtin.unarchive:
src: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch }}.tar.gz"
src: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}.tar.gz"
dest: "{{ mysqld_exporter_archive_path }}"
creates: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch }}/mysqld_exporter"
creates: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}/mysqld_exporter"
extra_opts:
- --no-same-owner
delegate_to: localhost
check_mode: false

- name: Propagate mysqld_exporter binaries
ansible.builtin.copy:
src: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ go_arch }}/mysqld_exporter"
src: "{{ mysqld_exporter_archive_path }}/mysqld_exporter-{{ mysqld_exporter_version }}.linux-{{ _mysqld_exporter_go_arch }}/mysqld_exporter"
dest: "{{ mysqld_exporter_binary_install_dir }}/mysqld_exporter"
mode: '0755'
owner: root
Expand Down
6 changes: 3 additions & 3 deletions roles/mysqld_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
ansible.builtin.set_fact:
__mysqld_exporter_checksums: "{{ lookup('url', mysqld_exporter_checksums_url, headers=_github_api_headers, wantlist=True) | list }}"
run_once: true
until: __mysqld_exporter_checksums is search('linux-' + go_arch + '.tar.gz')
until: __mysqld_exporter_checksums is search('linux-' + _mysqld_exporter_go_arch + '.tar.gz')
retries: 10

- name: "Get checksum for {{ go_arch }}"
- name: "Get checksum for {{ _mysqld_exporter_go_arch }}"
ansible.builtin.set_fact:
__mysqld_exporter_checksum: "{{ item.split(' ')[0] }}"
with_items: "{{ __mysqld_exporter_checksums }}"
when:
- "('linux-' + go_arch + '.tar.gz') in item"
- "('linux-' + _mysqld_exporter_go_arch + '.tar.gz') in item"
11 changes: 2 additions & 9 deletions roles/mysqld_exporter/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
---
go_arch_map:
i386: '386'
x86_64: 'amd64'
aarch64: 'arm64'
armv7l: 'armv7'
armv6l: 'armv6'

go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"

_mysqld_exporter_go_arch: "{{ {'i386': '386', 'x86_64': 'amd64', 'aarch64': 'arm64',
'armv7l': 'armv7', 'armv6l': 'armv6'}.get(ansible_architecture, ansible_architecture) }}"
_mysqld_exporter_repo: "prometheus/mysqld_exporter"
_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}"

Check failure on line 5 in roles/mysqld_exporter/vars/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

var-naming[no-role-prefix]

Variables names from within roles should use mysqld_exporter_ as a prefix. (vars: _github_api_headers)

0 comments on commit e9dcb24

Please sign in to comment.