Prototype the role

This commit is contained in:
Alexander Gorelyshev
2026-06-30 15:34:30 +04:00
parent 7c27d734fa
commit eb85fcac98
9 changed files with 151 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
---
ping_exporter_version: "v1.2.1"
ping_exporter_interval: "5s"
ping_exporter_timeout: "4s"
ping_exporter_history_size: 42
ping_exporter_payload_size: 56
ping_exporter_targets:
- "1.1.1.1"

View File

@@ -0,0 +1,7 @@
---
- name: "Restart-ping-exporter"
ansible.builtin.systemd:
name: ping_exporter
state: restarted
enabled: true
daemon_reload: true

View File

@@ -0,0 +1,15 @@
---
galaxy_info:
author: "Alexander Gorelyshev"
company: "Genlab, LLC"
description: "Deploy czerwonk/ping_exporter as a systemd unit"
license: "GPL-2.0-or-later"
min_ansible_version: "2.1"
platforms:
- name: "Ubuntu"
versions: ["focal"]
galaxy_tags: ["prometheus"]
dependencies: []

View File

@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
roles:
- role: "genlab.common.ping_exporter"
ping_exporter_targets:
- "127.0.0.1"

View File

@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ${MOLECULE_DISTRO:-ubuntu2404}
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,29 @@
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
tasks:
- name: "Include default vars"
ansible.builtin.include_vars:
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/"
extensions: ['yml']
# kics-scan ignore-block
- name: "Check if /metrics endpoint is reachable"
retries: 10
delay: 2
register: ping_exporter_metrics_check
until: ping_exporter_metrics_check.status == 200
ansible.builtin.uri:
url: "http://127.0.0.1:9427/metrics"
return_content: true
status_code: 200
timeout: 5
- name: "Fail if /metrics doesn't contain ping_exporter metrics"
ansible.builtin.assert:
that: "'ping_up' in ping_exporter_metrics_check.content"
fail_msg: "ping_exporter /metrics endpoint doesn't contain ping_up metrics!"
success_msg: "ping_up metrics availble from /metrics"

View File

@@ -0,0 +1,38 @@
---
# kics-scan disable=2e8d4922-8362-4606-8c14-aa10466a1ce3
- name: "Install the 'ping_exporter' package from Github (Debian)"
tags: ping_exporter
when: ansible_os_family == "Debian"
notify: "Restart-ping-exporter"
vars:
version: "{{ ping_exporter_version }}"
version_without_v: "{{ version | regex_replace('^v', '') }}"
base_url: "https://github.com/czerwonk/ping_exporter/releases/download"
full_url: "{{ base_url }}/{{ version }}/ping_exporter_{{ version_without_v }}_linux_amd64.deb"
ansible.builtin.apt:
deb: "{{ full_url }}"
state: present
- name: "Install the 'ping_exporter' package from Github (RHEL)"
tags: ping_exporter
when: ansible_os_family == "RHEL"
notify: "Restart-ping-exporter"
vars:
version: "{{ ping_exporter_version }}"
version_without_v: "{{ version | regex_replace('^v', '') }}"
base_url: "https://github.com/czerwonk/ping_exporter/releases/download"
full_url: "{{ base_url }}/{{ version }}/ping_exporter_{{ version_without_v }}_linux_amd64.rpm"
ansible.builtin.dnf:
name: "{{ full_url }}"
state: present
- name: "Push the configuration file"
tags: ping_exporter
notify: "Restart-ping-exporter"
ansible.builtin.template:
src: "config.yml.j2"
dest: "/etc/ping_exporter/config.yml"
owner: ping_exporter
group: root
mode: "0644"

View File

@@ -0,0 +1,19 @@
# List of target hosts (IP addresses or host names) to ping.
targets:
{% for target in ping_exporter_targets %}
- {{ target }}
{% endfor %}
dns:
# enforce a specific DNS server for host name lookups (optional,
# defaults to system rsesolver)
#nameserver: 1.1.1.1
# refresh interval for host name (optional)
#refresh: 2m45s
ping:
interval: {{ ping_exporter_interval }} # how often to ping a target?
timeout: {{ ping_exporter_timeout }} # timeout for a single ICMP Echo Request
history-size: {{ ping_exporter_history_size }} # number of results to keep per target
payload-size: {{ ping_exporter_payload_size }} # message size for ICMP Echo Requests

View File

@@ -0,0 +1 @@
---