mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-22 03:43:09 +00:00
chore: refactor for _common role
Signed-off-by: dobbi84 <davide.obbi@e4company.com>
This commit is contained in:
parent
02aefecad2
commit
6532e4745e
7 changed files with 38 additions and 115 deletions
|
@ -20,4 +20,4 @@ influxdb_exporter_system_group: "influxdb-exp"
|
|||
influxdb_exporter_system_user: "{{ influxdb_exporter_system_group }}"
|
||||
|
||||
# Local path to stash the archive and its extraction
|
||||
influxdb_exporter_archive_path: /tmp
|
||||
influxdb_exporter_local_cache_path: /tmp
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
---
|
||||
- name: Copy the influxdb_exporter systemd service file
|
||||
ansible.builtin.template:
|
||||
src: influxdb_exporter.service.j2
|
||||
dest: /etc/systemd/system/influxdb_exporter.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify: restart influxdb_exporter
|
||||
|
||||
- name: Allow influxdb_exporter port in SELinux on RedHat OS family
|
||||
community.general.seport:
|
||||
ports: "{{ influxdb_exporter_web_listen_address.split(':')[-1] }}"
|
||||
proto: tcp
|
||||
setype: http_port_t
|
||||
state: present
|
||||
when:
|
||||
- ansible_version.full is version_compare('2.4', '>=')
|
||||
- ansible_selinux.status == "enabled"
|
||||
- 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
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
---
|
||||
- name: Create the influxdb_exporter group
|
||||
ansible.builtin.group:
|
||||
name: "{{ influxdb_exporter_system_group }}"
|
||||
state: present
|
||||
system: true
|
||||
when: influxdb_exporter_system_group != "root"
|
||||
|
||||
- name: Create the influxdb_exporter user
|
||||
ansible.builtin.user:
|
||||
name: "{{ influxdb_exporter_system_user }}"
|
||||
groups: "{{ influxdb_exporter_system_group }}"
|
||||
append: true
|
||||
shell: /usr/sbin/nologin
|
||||
system: true
|
||||
create_home: false
|
||||
home: /
|
||||
when: influxdb_exporter_system_user != "root"
|
||||
|
||||
- name: Get binary
|
||||
when:
|
||||
- influxdb_exporter_binary_local_dir | length == 0
|
||||
- not influxdb_exporter_skip_install
|
||||
block:
|
||||
|
||||
- name: Download influxdb_exporter binary to local folder
|
||||
become: false
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ influxdb_exporter_binary_url }}"
|
||||
dest: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
checksum: "sha256:{{ __influxdb_exporter_checksum }}"
|
||||
mode: '0644'
|
||||
register: _download_binary
|
||||
until: _download_binary is succeeded
|
||||
retries: 5
|
||||
delay: 2
|
||||
delegate_to: localhost
|
||||
check_mode: false
|
||||
|
||||
- name: Unpack influxdb_exporter binary
|
||||
become: false
|
||||
ansible.builtin.unarchive:
|
||||
src: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
dest: "{{ influxdb_exporter_archive_path }}"
|
||||
creates: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}/influxdb_exporter"
|
||||
delegate_to: localhost
|
||||
check_mode: false
|
||||
|
||||
- name: Propagate influxdb_exporter binaries
|
||||
ansible.builtin.copy:
|
||||
src: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}/influxdb_exporter"
|
||||
dest: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter"
|
||||
mode: 0755
|
||||
owner: root
|
||||
group: root
|
||||
notify: restart influxdb_exporter
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Propagate locally distributed influxdb_exporter binary
|
||||
ansible.builtin.copy:
|
||||
src: "{{ influxdb_exporter_binary_local_dir }}/influxdb_exporter"
|
||||
dest: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter"
|
||||
mode: 0755
|
||||
owner: root
|
||||
group: root
|
||||
when:
|
||||
- influxdb_exporter_binary_local_dir | length > 0
|
||||
- not influxdb_exporter_skip_install
|
||||
notify: restart influxdb_exporter
|
|
@ -13,29 +13,32 @@
|
|||
- influxdb_exporter_run
|
||||
|
||||
- name: Install
|
||||
ansible.builtin.include_tasks:
|
||||
file: install.yml
|
||||
apply:
|
||||
become: true
|
||||
tags:
|
||||
- influxdb_exporter_install
|
||||
when:
|
||||
( not __influxdb_exporter_is_installed.stat.exists ) or
|
||||
( influxdb_exporter_binary_local_dir | length > 0 )
|
||||
ansible.builtin.include_role:
|
||||
name: prometheus.prometheus._common
|
||||
tasks_from: install.yml
|
||||
vars:
|
||||
_common_local_cache_path: "{{ influxdb_exporter_local_cache_path }}"
|
||||
_common_binaries: "{{ _influxdb_exporter_binaries }}"
|
||||
_common_binary_install_dir: "{{ influxdb_exporter_binary_install_dir }}"
|
||||
_common_binary_url: "{{ influxdb_exporter_binary_url }}"
|
||||
_common_checksums_url: "{{ influxdb_exporter_checksums_url }}"
|
||||
_common_system_group: "{{ influxdb_exporter_system_group }}"
|
||||
_common_system_user: "{{ influxdb_exporter_system_user }}"
|
||||
_common_binary_unarchive_opts: ['--strip-components=1']
|
||||
tags:
|
||||
- influxdb_exporter_install
|
||||
|
||||
- name: SELinux
|
||||
ansible.builtin.include_tasks:
|
||||
file: selinux.yml
|
||||
apply:
|
||||
become: true
|
||||
tags:
|
||||
- influxdb_exporter_configure
|
||||
ansible.builtin.include_role:
|
||||
name: prometheus.prometheus._common
|
||||
tasks_from: selinux.yml
|
||||
vars:
|
||||
_common_selinux_port: "{{ influxdb_exporter_web_listen_address | urlsplit('port') }}"
|
||||
when: ansible_selinux.status == "enabled"
|
||||
tags:
|
||||
- influxdb_exporter_configure
|
||||
|
||||
|
||||
- name: Configure
|
||||
ansible.builtin.include_tasks:
|
||||
file: configure.yml
|
||||
|
@ -57,3 +60,4 @@
|
|||
- not ansible_check_mode
|
||||
tags:
|
||||
- influxdb_exporter_run
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
---
|
||||
- name: Common preflight
|
||||
ansible.builtin.include_role:
|
||||
name: prometheus.prometheus._common
|
||||
tasks_from: preflight.yml
|
||||
|
||||
- name: Assert usage of systemd as an init system
|
||||
ansible.builtin.assert:
|
||||
that: ansible_service_mgr == 'systemd'
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
- name: Install selinux python packages [RedHat]
|
||||
ansible.builtin.package:
|
||||
name: "{{ ['libselinux-python', 'policycoreutils-python']
|
||||
if ansible_python_version is version('3', '<') else
|
||||
['python3-libselinux', 'python3-policycoreutils'] }}"
|
||||
state: present
|
||||
register: _install_selinux_packages
|
||||
until: _install_selinux_packages is success
|
||||
retries: 5
|
||||
delay: 2
|
||||
when: ansible_os_family | lower == "redhat"
|
|
@ -9,3 +9,5 @@ go_arch_map:
|
|||
go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
|
||||
_influxdb_exporter_repo: "prometheus/influxdb_exporter"
|
||||
_influxdb_exporter_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}"
|
||||
|
||||
_influxdb_exporter_binaries: ['influxdb_exporter']
|
||||
|
|
Loading…
Reference in a new issue