From 151896ba051974e974fd8e8669bab7ecfcfbd0b5 Mon Sep 17 00:00:00 2001 From: Marcus Klein Date: Mon, 25 Nov 2024 14:51:55 +0100 Subject: [PATCH] Use variables from ansible_facts in mysqld_exporter role to allow ANSIBLE_INJECT_FACT_VARS to become false --- roles/mysqld_exporter/defaults/main.yml | 4 ++-- roles/mysqld_exporter/meta/argument_specs.yml | 4 ++-- roles/mysqld_exporter/tasks/main.yml | 2 +- roles/mysqld_exporter/templates/mysqld_exporter.service.j2 | 2 +- roles/mysqld_exporter/vars/main.yml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/roles/mysqld_exporter/defaults/main.yml b/roles/mysqld_exporter/defaults/main.yml index a66cf335c..d1b832967 100644 --- a/roles/mysqld_exporter/defaults/main.yml +++ b/roles/mysqld_exporter/defaults/main.yml @@ -1,7 +1,7 @@ --- mysqld_exporter_version: 0.16.0 mysqld_exporter_binary_url: "https://github.com/{{ _mysqld_exporter_repo }}/releases/download/v{{ mysqld_exporter_version }}/\ - mysqld_exporter-{{ mysqld_exporter_version }}.{{ ansible_system | lower }}-{{ _mysqld_exporter_go_ansible_arch }}.tar.gz" + mysqld_exporter-{{ mysqld_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _mysqld_exporter_go_ansible_arch }}.tar.gz" mysqld_exporter_checksums_url: "https://github.com/{{ _mysqld_exporter_repo }}/releases/download/v{{ mysqld_exporter_version }}/sha256sums.txt" mysqld_exporter_web_listen_address: "0.0.0.0:9104" @@ -34,4 +34,4 @@ mysqld_exporter_system_group: "mysqld-exp" mysqld_exporter_system_user: "{{ mysqld_exporter_system_group }}" # Local path to stash the archive and its extraction -mysqld_exporter_local_cache_path: "/tmp/mysqld_exporter-{{ ansible_system | lower }}-{{ _mysqld_exporter_go_ansible_arch }}/{{ mysqld_exporter_version }}" +mysqld_exporter_local_cache_path: "/tmp/mysqld_exporter-{{ ansible_facts['system'] | lower }}-{{ _mysqld_exporter_go_ansible_arch }}/{{ mysqld_exporter_version }}" diff --git a/roles/mysqld_exporter/meta/argument_specs.yml b/roles/mysqld_exporter/meta/argument_specs.yml index 49dccf2e9..4253f3ba7 100644 --- a/roles/mysqld_exporter/meta/argument_specs.yml +++ b/roles/mysqld_exporter/meta/argument_specs.yml @@ -13,7 +13,7 @@ argument_specs: default: "0.16.0" mysqld_exporter_binary_url: description: "URL of the mysqld_exporter binaries .tar.gz file" - default: "https://github.com/{{ _mysqld_exporter_repo }}/releases/download/v{{ mysqld_exporter_version }}/mysqld_exporter-{{ mysqld_exporter_version }}.{{ ansible_system | lower }}-{{ _mysqld_exporter_go_ansible_arch }}.tar.gz" + default: "https://github.com/{{ _mysqld_exporter_repo }}/releases/download/v{{ mysqld_exporter_version }}/mysqld_exporter-{{ mysqld_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _mysqld_exporter_go_ansible_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" @@ -84,4 +84,4 @@ argument_specs: default: "mysqld-exp" mysqld_exporter_local_cache_path: description: "Local path to stash the archive and its extraction" - default: "/tmp/mysqld_exporter-{{ ansible_system | lower }}-{{ _mysqld_exporter_go_ansible_arch }}/{{ mysqld_exporter_version }}" + default: "/tmp/mysqld_exporter-{{ ansible_facts['system'] | lower }}-{{ _mysqld_exporter_go_ansible_arch }}/{{ mysqld_exporter_version }}" diff --git a/roles/mysqld_exporter/tasks/main.yml b/roles/mysqld_exporter/tasks/main.yml index 57a594415..6591444df 100644 --- a/roles/mysqld_exporter/tasks/main.yml +++ b/roles/mysqld_exporter/tasks/main.yml @@ -30,7 +30,7 @@ tasks_from: selinux.yml vars: _common_selinux_port: "{{ mysqld_exporter_web_listen_address | urlsplit('port') }}" - when: ansible_selinux.status == "enabled" + when: ansible_facts['selinux'].status == "enabled" tags: - mysqld_exporter_configure diff --git a/roles/mysqld_exporter/templates/mysqld_exporter.service.j2 b/roles/mysqld_exporter/templates/mysqld_exporter.service.j2 index 9180e53c0..56ad1dfae 100644 --- a/roles/mysqld_exporter/templates/mysqld_exporter.service.j2 +++ b/roles/mysqld_exporter/templates/mysqld_exporter.service.j2 @@ -45,7 +45,7 @@ RestartSec=1 StartLimitInterval=0 {% set protect_home = 'yes' %} -{% for m in ansible_mounts if m.mount.startswith('/home') %} +{% for m in ansible_facts['mounts'] if m.mount.startswith('/home') %} {% set protect_home = 'read-only' %} {% endfor %} ProtectHome={{ protect_home }} diff --git a/roles/mysqld_exporter/vars/main.yml b/roles/mysqld_exporter/vars/main.yml index 7d8442e98..9f003eb83 100644 --- a/roles/mysqld_exporter/vars/main.yml +++ b/roles/mysqld_exporter/vars/main.yml @@ -3,7 +3,7 @@ _mysqld_exporter_go_ansible_arch: "{{ {'i386': '386', 'x86_64': 'amd64', 'aarch64': 'arm64', 'armv7l': 'armv7', - 'armv6l': 'armv6'}.get(ansible_architecture, ansible_architecture) }}" + 'armv6l': 'armv6'}.get(ansible_facts['architecture'], ansible_facts['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 {} }}" _mysqld_exporter_binaries: ['mysqld_exporter']