ansible-collection-prometheus/roles/fail2ban_exporter/tasks/preflight.yml
Oleg Klyuchkin ee540fe8de
skip_changelog(ci): gitlab.com support for version updater (#308)
* ci: gitlab.com support for version updater

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* ci: version updater fix syntax

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* test: version updater fix sanity

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* test: version updater add gitlab_api function

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>

* feat: version updater use case statement

Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Oleg Klyuchkin <anviar@users.noreply.github.com>

---------

Signed-off-by: anviar <oleg.kluchkin+github@gmail.com>
Signed-off-by: Oleg Klyuchkin <anviar@users.noreply.github.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
2024-02-29 09:48:53 +01:00

85 lines
2.9 KiB
YAML

---
- name: Assert usage of systemd as an init system
ansible.builtin.assert:
that: ansible_service_mgr == 'systemd'
msg: "This role only works with systemd"
- name: Install package fact dependencies
become: true
ansible.builtin.package:
name: "{{ _pkg_fact_req }}"
state: present
when: (_pkg_fact_req)
vars:
_pkg_fact_req: "{% if (ansible_pkg_mgr == 'apt') %}\
{{ ('python-apt' if ansible_python_version is version('3', '<') else 'python3-apt') }}
{% else %}\
{% endif %}"
- name: Gather package facts
ansible.builtin.package_facts:
when: "not 'packages' in ansible_facts"
- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
fail2ban_exporter_web_listen_address is string
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[fail2ban_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Check if fail2ban_exporter is installed
ansible.builtin.stat:
path: "{{ fail2ban_exporter_binary_install_dir }}/fail2ban_exporter"
register: __fail2ban_exporter_is_installed
check_mode: false
tags:
- fail2ban_exporter_install
- name: Gather currently installed fail2ban_exporter version (if any)
ansible.builtin.command: "{{ fail2ban_exporter_binary_install_dir }}/fail2ban_exporter --version"
changed_when: false
register: __fail2ban_exporter_current_version_output
check_mode: false
when: __fail2ban_exporter_is_installed.stat.exists
tags:
- fail2ban_exporter_install
- name: Discover latest version
ansible.builtin.set_fact:
fail2ban_exporter_version: "{{ (lookup('url', 'https://gitlab.com/api/v4/projects/{{ _fail2ban_exporter_repo }}/releases',
split_lines=False) | from_json)[0].get('tag_name') | replace('v', '') }}"
run_once: true
until: fail2ban_exporter_version is version('0.0.0', '>=')
retries: 10
when:
- fail2ban_exporter_version == "latest"
- fail2ban_exporter_binary_local_dir | length == 0
- not fail2ban_exporter_skip_install
- name: Get fail2ban_exporter binary checksum
when:
- fail2ban_exporter_binary_local_dir | length == 0
- not fail2ban_exporter_skip_install
block:
- name: Get checksum list from gitlab
ansible.builtin.set_fact:
__fail2ban_exporter_checksums: "{{ lookup('url', fail2ban_exporter_checksums_url, wantlist=True) | list }}"
run_once: true
until: __fail2ban_exporter_checksums is search('linux_' + go_arch + '.tar.gz')
retries: 10
- name: "Get checksum for {{ go_arch }}"
ansible.builtin.set_fact:
__fail2ban_exporter_checksum: "{{ item.split(' ')[0] }}"
with_items: "{{ __fail2ban_exporter_checksums }}"
when:
- "item.endswith('fail2ban_exporter_' + fail2ban_exporter_version + '_linux_' + go_arch + '.tar.gz')"