From e9dcb24ba3f34961d13f43c6e40ec0dac44c8404 Mon Sep 17 00:00:00 2001 From: gardar Date: Thu, 20 Jun 2024 02:53:00 +0000 Subject: [PATCH] fix(mysqld_exporter): simplify go architecture variable Signed-off-by: gardar --- roles/mysqld_exporter/defaults/main.yml | 2 +- roles/mysqld_exporter/meta/argument_specs.yml | 3 ++- .../molecule/alternative/molecule.yml | 2 +- .../molecule/alternative/prepare.yml | 14 +++++--------- roles/mysqld_exporter/tasks/install.yml | 8 ++++---- roles/mysqld_exporter/tasks/preflight.yml | 6 +++--- roles/mysqld_exporter/vars/main.yml | 11 ++--------- 7 files changed, 18 insertions(+), 28 deletions(-) diff --git a/roles/mysqld_exporter/defaults/main.yml b/roles/mysqld_exporter/defaults/main.yml index 3e7a6c2d5..f192e4b2a 100644 --- a/roles/mysqld_exporter/defaults/main.yml +++ b/roles/mysqld_exporter/defaults/main.yml @@ -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 diff --git a/roles/mysqld_exporter/meta/argument_specs.yml b/roles/mysqld_exporter/meta/argument_specs.yml index d2e82e371..92031511e 100644 --- a/roles/mysqld_exporter/meta/argument_specs.yml +++ b/roles/mysqld_exporter/meta/argument_specs.yml @@ -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" diff --git a/roles/mysqld_exporter/molecule/alternative/molecule.yml b/roles/mysqld_exporter/molecule/alternative/molecule.yml index b5a4cec86..8c7e7755d 100644 --- a/roles/mysqld_exporter/molecule/alternative/molecule.yml +++ b/roles/mysqld_exporter/molecule/alternative/molecule.yml @@ -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 diff --git a/roles/mysqld_exporter/molecule/alternative/prepare.yml b/roles/mysqld_exporter/molecule/alternative/prepare.yml index 5de30467b..208837dfc 100644 --- a/roles/mysqld_exporter/molecule/alternative/prepare.yml +++ b/roles/mysqld_exporter/molecule/alternative/prepare.yml @@ -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 @@ -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 diff --git a/roles/mysqld_exporter/tasks/install.yml b/roles/mysqld_exporter/tasks/install.yml index e114d666c..1b2fcf948 100644 --- a/roles/mysqld_exporter/tasks/install.yml +++ b/roles/mysqld_exporter/tasks/install.yml @@ -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 @@ -40,9 +40,9 @@ - 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 @@ -50,7 +50,7 @@ - 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 diff --git a/roles/mysqld_exporter/tasks/preflight.yml b/roles/mysqld_exporter/tasks/preflight.yml index f7c09c8a1..f8d2db271 100644 --- a/roles/mysqld_exporter/tasks/preflight.yml +++ b/roles/mysqld_exporter/tasks/preflight.yml @@ -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" diff --git a/roles/mysqld_exporter/vars/main.yml b/roles/mysqld_exporter/vars/main.yml index ab80cc61d..386b6c528 100644 --- a/roles/mysqld_exporter/vars/main.yml +++ b/roles/mysqld_exporter/vars/main.yml @@ -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 {} }}"