chore: fix post review on refactor for _commons role

Signed-off-by: dobbi84 <davide.obbi@e4company.com>
This commit is contained in:
dobbi84 2024-10-18 15:12:07 +02:00 committed by gardar
parent 9cd3949895
commit ccad1f4143
7 changed files with 44 additions and 68 deletions

View file

@ -1,6 +1,5 @@
---
influxdb_exporter_version: "0.11.5"
influxdb_exporter_binary_local_dir: ""
influxdb_exporter_binary_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/\
influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
influxdb_exporter_checksums_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt"

View file

@ -15,11 +15,6 @@ argument_specs:
description: "influxdb exporter installation tasks gets skipped when set to true."
type: bool
default: false
influxdb_exporter_binary_local_dir:
description:
- "Enables the use of local packages instead of those distributed on github."
- "The parameter may be set to a directory where the C(influxdb_exporter) binary is stored on the host where ansible is run."
- "This overrides the I(influxdb_exporter_version) parameter"
influxdb_exporter_binary_url:
description: "URL of the influxdb exporter binaries .tar.gz file"
default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"

View file

@ -5,7 +5,6 @@ provisioner:
inventory:
group_vars:
all:
influxdb_exporter_binary_local_dir: "/tmp/influxdb_exporter-linux-amd64"
influxdb_exporter_web_listen_address: '127.0.0.1:8080'
go_arch: amd64

View file

@ -1,35 +0,0 @@
---
- name: Run local preparation
hosts: localhost
gather_facts: false
tasks:
- name: Download influxdb_exporter binary to local folder
become: false
ansible.builtin.get_url:
url: "https://github.com/prometheus/influxdb_exporter/releases/download/v{{\
\ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{\
\ go_arch }}.tar.gz"
dest: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
mode: 0644
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
check_mode: false
- name: Unpack influxdb_exporter binary
become: false
ansible.builtin.unarchive:
src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
dest: "/tmp"
creates: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch\
\ }}/influxdb_exporter"
check_mode: false
- name: Link to influxdb_exporter binaries directory
become: false
ansible.builtin.file:
src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-amd64"
dest: "/tmp/influxdb_exporter-linux-amd64"
state: link
check_mode: false

View file

@ -1,12 +0,0 @@
---
- name: Configure
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: configure.yml
vars:
_common_system_user: "{{ influxdb_exporter_system_user }}"
_common_system_group: "{{ influxdb_exporter_system_group }}"
tags:
- influxdb_exporter
- configure
- influxdb_exporter_configure

View file

@ -2,12 +2,11 @@
- name: Preflight
ansible.builtin.include_tasks:
file: preflight.yml
apply:
tags:
- influxdb_exporter_install
- influxdb_exporter_configure
- influxdb_exporter_run
tags:
- influxdb_exporter
- install
- configure
- run
- influxdb_exporter_install
- influxdb_exporter_configure
- influxdb_exporter_run
@ -26,6 +25,8 @@
_common_system_user: "{{ influxdb_exporter_system_user }}"
_common_binary_unarchive_opts: ['--strip-components=1']
tags:
- influxdb_exporter
- install
- influxdb_exporter_install
- name: SELinux
@ -36,17 +37,20 @@
_common_selinux_port: "{{ influxdb_exporter_web_listen_address | urlsplit('port') }}"
when: ansible_selinux.status == "enabled"
tags:
- influxdb_exporter
- configure
- influxdb_exporter_configure
- name: Configure
ansible.builtin.include_tasks:
file: configure.yml
apply:
become: true
tags:
- influxdb_exporter_configure
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: configure.yml
vars:
_common_system_user: "{{ influxdb_exporter_system_user }}"
_common_system_group: "{{ influxdb_exporter_system_group }}"
tags:
- influxdb_exporter
- configure
- influxdb_exporter_configure
- name: Ensure Influxdb Exporter is enabled on boot
@ -59,5 +63,7 @@
when:
- not ansible_check_mode
tags:
- influxdb_exporter
- run
- influxdb_exporter_run

View file

@ -3,11 +3,19 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
tags:
- influxdb_exporter
- preflight
- influxdb_exporter_preflight
- name: Assert usage of systemd as an init system
ansible.builtin.assert:
that: ansible_service_mgr == 'systemd'
msg: "This role only works with systemd"
tags:
- influxdb_exporter
- preflight
- influxdb_exporter_preflight
- name: Naive assertion of proper listen address
ansible.builtin.assert:
@ -18,6 +26,10 @@
reject('match', '.+:\\d+$') |
list |
length == 0
tags:
- influxdb_exporter
- preflight
- influxdb_exporter_preflight
- name: Check if influxdb_exporter is installed
ansible.builtin.stat:
@ -25,6 +37,8 @@
register: __influxdb_exporter_is_installed
check_mode: false
tags:
- influxdb_exporter
- install
- influxdb_exporter_install
- name: Discover latest version
@ -36,12 +50,16 @@
retries: 10
when:
- influxdb_exporter_version == "latest"
- influxdb_exporter_binary_local_dir | length == 0
- not influxdb_exporter_skip_install
tags:
- influxdb_exporter
- install
- influxdb_exporter_install
- download
- influxdb_exporter_download
- name: Get influxdb_exporter binary checksum
when:
- influxdb_exporter_binary_local_dir | length == 0
- not influxdb_exporter_skip_install
block:
- name: Get checksum list from github
@ -57,3 +75,9 @@
with_items: "{{ __influxdb_exporter_checksums }}"
when:
- "('linux-' + go_arch + '.tar.gz') in item"
tags:
- influxdb_exporter
- install
- influxdb_exporter_install
- download
- influxdb_exporter_download