mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-10 06:14:13 +00:00
Merge pull request #128 from prometheus-community/superq/smokeping_prober
feat: Add role smokeping_prober
This commit is contained in:
commit
ebeb5097ce
30 changed files with 927 additions and 0 deletions
84
roles/smokeping_prober/README.md
Normal file
84
roles/smokeping_prober/README.md
Normal file
|
@ -0,0 +1,84 @@
|
|||
<p><img src="https://www.circonus.com/wp-content/uploads/2015/03/sol-icon-itOps.png" alt="graph logo" title="graph" align="right" height="60" /></p>
|
||||
|
||||
# Ansible Role: smokeping_prober
|
||||
|
||||
Deploy prometheus [smokeping_prober](https://github.com/superq/smokeping_prober) using ansible.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Ansible >= 2.9 (It might work on previous versions, but we cannot guarantee it)
|
||||
- gnu-tar on Mac deployer host (`brew install gnu-tar`)
|
||||
- Passlib is required when using the basic authentication feature (`pip install passlib[bcrypt]`)
|
||||
|
||||
## Role Variables
|
||||
All variables which can be overridden are stored in [defaults/main.yml](defaults/main.yml) file as well as in [meta/argument_specs.yml](meta/argument_specs.yml).
|
||||
Please refer to the [collection docs](https://prometheus-community.github.io/ansible/branch/main/smokeping_prober_role.html) for description and default values of the variables.
|
||||
|
||||
## Example
|
||||
|
||||
### Playbook
|
||||
|
||||
Use it in a playbook as follows:
|
||||
```yaml
|
||||
- hosts: all
|
||||
collections:
|
||||
- prometheus.prometheus
|
||||
roles:
|
||||
- prometheus.prometheus.smokeping_prober
|
||||
```
|
||||
|
||||
### TLS config
|
||||
|
||||
Before running smokeping_prober role, the user needs to provision their own certificate and key.
|
||||
```yaml
|
||||
- hosts: all
|
||||
pre_tasks:
|
||||
- name: Create smokeping_prober cert dir
|
||||
ansible.builtin.file:
|
||||
path: "/etc/smokeping_prober"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: Create cert and key
|
||||
community.crypto.x509_certificate:
|
||||
path: /etc/smokeping_prober/tls.cert
|
||||
csr_path: /etc/smokeping_prober/tls.csr
|
||||
privatekey_path: /etc/smokeping_prober/tls.key
|
||||
provider: selfsigned
|
||||
collections:
|
||||
- prometheus.prometheus
|
||||
roles:
|
||||
- prometheus.prometheus.smokeping_prober
|
||||
vars:
|
||||
smokeping_prober_tls_server_config:
|
||||
cert_file: /etc/smokeping_prober/tls.cert
|
||||
key_file: /etc/smokeping_prober/tls.key
|
||||
smokeping_prober_basic_auth_users:
|
||||
randomuser: examplepassword
|
||||
```
|
||||
|
||||
|
||||
### Demo site
|
||||
|
||||
We provide an example site that demonstrates a full monitoring solution based on prometheus and grafana. The repository with code and links to running instances is [available on github](https://github.com/prometheus/demo-site) and the site is hosted on [DigitalOcean](https://digitalocean.com).
|
||||
|
||||
## Local Testing
|
||||
|
||||
The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/ansible-community/molecule) (v3.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable for your system. Running your tests is as simple as executing `molecule test`.
|
||||
|
||||
## Continuous Integration
|
||||
|
||||
Combining molecule and circle CI allows us to test how new PRs will behave when used with multiple ansible versions and multiple operating systems. This also allows use to create test scenarios for different role configurations. As a result we have quite a large test matrix which can take more time than local testing, so please be patient.
|
||||
|
||||
## Contributing
|
||||
|
||||
See [contributor guideline](CONTRIBUTING.md).
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
See [troubleshooting](TROUBLESHOOTING.md).
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details.
|
20
roles/smokeping_prober/TROUBLESHOOTING.md
Normal file
20
roles/smokeping_prober/TROUBLESHOOTING.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Troubleshooting
|
||||
|
||||
## Bad requests (HTTP 400)
|
||||
|
||||
This role downloads checksums from the Github project to verify the integrity of artifacts installed on your servers. When downloading the checksums, a "bad request" error might occur.
|
||||
|
||||
This happens in environments which (knowningly or unknowling) use the [netrc mechanism](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html) to auto-login into servers.
|
||||
|
||||
Unless netrc is needed by your playbook and ansible roles, please unset the var like so:
|
||||
|
||||
```
|
||||
$ NETRC= ansible-playbook ...
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```
|
||||
$ export NETRC=
|
||||
$ ansible-playbook ...
|
||||
```
|
35
roles/smokeping_prober/defaults/main.yml
Normal file
35
roles/smokeping_prober/defaults/main.yml
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
smokeping_prober_version: 0.7.0
|
||||
smokeping_prober_binary_local_dir: ""
|
||||
smokeping_prober_binary_url: "https://github.com/{{ _smokeping_prober_repo }}/releases/download/v{{ smokeping_prober_version }}/\
|
||||
smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
smokeping_prober_checksums_url: "https://github.com/{{ _smokeping_prober_repo }}/releases/download/v{{ smokeping_prober_version }}/sha256sums.txt"
|
||||
smokeping_prober_skip_install: false
|
||||
|
||||
smokeping_prober_web_listen_address: ":9374"
|
||||
smokeping_prober_web_telemetry_path: "/metrics"
|
||||
|
||||
# List of smokeping_prober targets.
|
||||
# See: https://github.com/SuperQ/smokeping_prober/#configuration
|
||||
smokeping_prober_targets:
|
||||
- hosts:
|
||||
- localhost
|
||||
interval: 1s # Duration, Default 1s.
|
||||
network: ip # One of ip, ip4, ip6. Default: ip (automatic IPv4/IPv6)
|
||||
protocol: icmp # One of icmp, udp. Default: icmp (Requires privileged operation)
|
||||
size: 56 # Packet data size in bytes. Default 56 (Range: 24 - 65535)
|
||||
source: 127.0.1.1 # Souce IP address to use. Default: None (automatic selection)
|
||||
|
||||
smokeping_prober_config_file: "probes.yml"
|
||||
|
||||
smokeping_prober_tls_server_config: {}
|
||||
|
||||
smokeping_prober_http_server_config: {}
|
||||
|
||||
smokeping_prober_basic_auth_users: {}
|
||||
|
||||
# Internal variables.
|
||||
smokeping_prober_binary_install_dir: "/usr/local/bin"
|
||||
smokeping_prober_config_dir: "/etc/smokeping_prober"
|
||||
smokeping_prober_system_group: "smokeping"
|
||||
smokeping_prober_system_user: "{{ smokeping_prober_system_group }}"
|
10
roles/smokeping_prober/handlers/main.yml
Normal file
10
roles/smokeping_prober/handlers/main.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
- name: Restart smokeping_prober
|
||||
listen: "restart smokeping_prober"
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
name: smokeping_prober
|
||||
state: restarted
|
||||
when:
|
||||
- not ansible_check_mode
|
65
roles/smokeping_prober/meta/argument_specs.yml
Normal file
65
roles/smokeping_prober/meta/argument_specs.yml
Normal file
|
@ -0,0 +1,65 @@
|
|||
---
|
||||
# yamllint disable rule:line-length
|
||||
argument_specs:
|
||||
main:
|
||||
short_description: "Prometheus Smokeping Prober"
|
||||
description:
|
||||
- "Deploy prometheus L(Smokeping Prober,https://github.com/superq/smokeping_prober) using ansible"
|
||||
author:
|
||||
- "Prometheus Community"
|
||||
options:
|
||||
smokeping_prober_version:
|
||||
description: "Smokeping Prober package version. Also accepts latest as parameter."
|
||||
default: "1.1.2"
|
||||
smokeping_prober_skip_install:
|
||||
description: "Smokeping Prober installation tasks gets skipped when set to true."
|
||||
type: bool
|
||||
default: false
|
||||
smokeping_prober_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(smokeping_prober) binary is stored on the host where ansible is run."
|
||||
- "This overrides the I(smokeping_prober_version) parameter"
|
||||
smokeping_prober_binary_url:
|
||||
description: "URL of the Smokeping Prober binaries .tar.gz file"
|
||||
default: "https://github.com/{{ _smokeping_prober_repo }}/releases/download/v{{ smokeping_prober_version }}/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
smokeping_prober_checksums_url:
|
||||
description: "URL of the Smokeping Prober checksums file"
|
||||
default: "https://github.com/{{ _smokeping_prober_repo }}/releases/download/v{{ smokeping_prober_version }}/sha256sums.txt"
|
||||
smokeping_prober_web_listen_address:
|
||||
description: "Address on which Smokeping Prober will listen"
|
||||
default: "0.0.0.0:9374"
|
||||
smokeping_prober_web_telemetry_path:
|
||||
description: "Path under which to expose metrics"
|
||||
default: "/metrics"
|
||||
smokeping_prober_config_file:
|
||||
description: "The filename of the smokeping_prober probes config file"
|
||||
default: "probes.yml"
|
||||
smokeping_prober_tls_server_config:
|
||||
description:
|
||||
- "Configuration for TLS authentication."
|
||||
- "Keys and values are the same as in L(smokeping_prober docs,https://github.com/superq/smokeping_prober/blob/master/https/README.md#sample-config)."
|
||||
type: "dict"
|
||||
smokeping_prober_http_server_config:
|
||||
description:
|
||||
- "Config for HTTP/2 support."
|
||||
- "Keys and values are the same as in L(smokeping_prober docs,https://github.com/superq/smokeping_prober/blob/master/https/README.md#sample-config)."
|
||||
type: "dict"
|
||||
smokeping_prober_basic_auth_users:
|
||||
description: "Dictionary of users and password for basic authentication. Passwords are automatically hashed with bcrypt."
|
||||
type: "dict"
|
||||
smokeping_prober_binary_install_dir:
|
||||
description:
|
||||
- "I(Advanced)"
|
||||
- "Directory to install smokeping_prober binary"
|
||||
default: "/usr/local/bin"
|
||||
smokeping_prober_system_group:
|
||||
description:
|
||||
- "I(Advanced)"
|
||||
- "System group for Smokeping Prober"
|
||||
default: "smokeping"
|
||||
smokeping_prober_system_user:
|
||||
description:
|
||||
- "I(Advanced)"
|
||||
- "Smokeping Prober user"
|
||||
default: "smokeping"
|
31
roles/smokeping_prober/meta/main.yml
Normal file
31
roles/smokeping_prober/meta/main.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
galaxy_info:
|
||||
author: "Prometheus Community"
|
||||
description: "Prometheus Smokeping Prober"
|
||||
license: "Apache"
|
||||
min_ansible_version: "2.9"
|
||||
platforms:
|
||||
- name: "Ubuntu"
|
||||
versions:
|
||||
- "bionic"
|
||||
- "focal"
|
||||
- "jammy"
|
||||
- name: "Debian"
|
||||
versions:
|
||||
- "bullseye"
|
||||
- "buster"
|
||||
- name: "EL"
|
||||
versions:
|
||||
- "7"
|
||||
- "8"
|
||||
- "9"
|
||||
- name: "Fedora"
|
||||
versions:
|
||||
- "36"
|
||||
- "37"
|
||||
galaxy_tags:
|
||||
- "monitoring"
|
||||
- "prometheus"
|
||||
- "exporter"
|
||||
- "metrics"
|
||||
- "system"
|
36
roles/smokeping_prober/molecule/alternative/converge.yml
Normal file
36
roles/smokeping_prober/molecule/alternative/converge.yml
Normal file
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
- name: Run role
|
||||
hosts: all
|
||||
any_errors_fatal: true
|
||||
roles:
|
||||
- prometheus.prometheus.smokeping_prober
|
||||
pre_tasks:
|
||||
- name: Create smokeping_prober cert dir
|
||||
ansible.builtin.file:
|
||||
path: "{{ smokeping_prober_tls_server_config.cert_file | dirname }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: u+rwX,g+rwX,o=rX
|
||||
|
||||
- name: Copy cert and key
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
mode: "{{ item.mode | default('0644') }}"
|
||||
loop:
|
||||
- src: "/tmp/tls.cert"
|
||||
dest: "{{ smokeping_prober_tls_server_config.cert_file }}"
|
||||
- src: "/tmp/tls.key"
|
||||
dest: "{{ smokeping_prober_tls_server_config.key_file }}"
|
||||
vars:
|
||||
smokeping_prober_binary_local_dir: "/tmp/smokeping_prober-linux-amd64"
|
||||
smokeping_prober_web_listen_address: "127.0.0.1:8080"
|
||||
|
||||
smokeping_prober_tls_server_config:
|
||||
cert_file: /etc/smokeping_prober/tls.cert
|
||||
key_file: /etc/smokeping_prober/tls.key
|
||||
smokeping_prober_http_server_config:
|
||||
http2: true
|
||||
smokeping_prober_basic_auth_users:
|
||||
randomuser: examplepassword
|
1
roles/smokeping_prober/molecule/alternative/molecule.yml
Normal file
1
roles/smokeping_prober/molecule/alternative/molecule.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
56
roles/smokeping_prober/molecule/alternative/prepare.yml
Normal file
56
roles/smokeping_prober/molecule/alternative/prepare.yml
Normal file
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
- name: Prepare
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
go_arch: amd64
|
||||
smokeping_prober_version: 0.6.1
|
||||
tasks:
|
||||
- name: Download smokeping_prober binary to local folder
|
||||
become: false
|
||||
ansible.builtin.get_url:
|
||||
url: "https://github.com/superq/smokeping_prober/releases/download/v{{ smokeping_prober_version }}/\
|
||||
smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
dest: "/tmp/smokeping_prober-{{ smokeping_prober_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 smokeping_prober binary
|
||||
become: false
|
||||
ansible.builtin.unarchive:
|
||||
src: "/tmp/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
dest: "/tmp"
|
||||
creates: "/tmp/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}/smokeping_prober"
|
||||
check_mode: false
|
||||
|
||||
- name: Link to smokeping_prober binaries directory
|
||||
become: false
|
||||
ansible.builtin.file:
|
||||
src: "/tmp/smokeping_prober-{{ smokeping_prober_version }}.linux-amd64"
|
||||
dest: "/tmp/smokeping_prober-linux-amd64"
|
||||
state: link
|
||||
check_mode: false
|
||||
|
||||
- name: Install pyOpenSSL for certificate generation
|
||||
ansible.builtin.pip:
|
||||
name: "pyOpenSSL"
|
||||
|
||||
- name: Create private key
|
||||
community.crypto.openssl_privatekey:
|
||||
path: "/tmp/tls.key"
|
||||
|
||||
- name: Create CSR
|
||||
community.crypto.openssl_csr:
|
||||
path: "/tmp/tls.csr"
|
||||
privatekey_path: "/tmp/tls.key"
|
||||
|
||||
- name: Create certificate
|
||||
community.crypto.x509_certificate:
|
||||
path: "/tmp/tls.cert"
|
||||
csr_path: "/tmp/tls.csr"
|
||||
privatekey_path: "/tmp/tls.key"
|
||||
provider: selfsigned
|
|
@ -0,0 +1,39 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import testinfra.utils.ansible_runner
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||
|
||||
|
||||
def test_directories(host):
|
||||
dirs = [
|
||||
"/etc/smokeping_prober"
|
||||
]
|
||||
for dir in dirs:
|
||||
d = host.file(dir)
|
||||
assert d.is_directory
|
||||
assert d.exists
|
||||
|
||||
|
||||
def test_service(host):
|
||||
s = host.service("smokeping_prober")
|
||||
# assert s.is_enabled
|
||||
assert s.is_running
|
||||
|
||||
|
||||
def test_protecthome_property(host):
|
||||
s = host.service("smokeping_prober")
|
||||
p = s.systemd_properties
|
||||
assert p.get("ProtectHome") == "yes"
|
||||
|
||||
|
||||
def test_socket(host):
|
||||
sockets = [
|
||||
"tcp://127.0.0.1:8080"
|
||||
]
|
||||
for socket in sockets:
|
||||
s = host.socket(socket)
|
||||
assert s.is_listening
|
8
roles/smokeping_prober/molecule/default/converge.yml
Normal file
8
roles/smokeping_prober/molecule/default/converge.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
any_errors_fatal: true
|
||||
roles:
|
||||
- prometheus.prometheus.smokeping_prober
|
||||
vars:
|
||||
smokeping_prober_web_listen_address: "127.0.0.1:9374"
|
1
roles/smokeping_prober/molecule/default/molecule.yml
Normal file
1
roles/smokeping_prober/molecule/default/molecule.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
|
@ -0,0 +1,72 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import testinfra.utils.ansible_runner
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||
|
||||
|
||||
def test_directories(host):
|
||||
dirs = [
|
||||
"/etc/smokeping_prober"
|
||||
]
|
||||
for dir in dirs:
|
||||
d = host.file(dir)
|
||||
assert d.is_directory
|
||||
assert d.exists
|
||||
|
||||
|
||||
def test_files(host):
|
||||
files = [
|
||||
"/etc/systemd/system/smokeping_prober.service",
|
||||
"/usr/local/bin/smokeping_prober"
|
||||
]
|
||||
for file in files:
|
||||
f = host.file(file)
|
||||
assert f.exists
|
||||
assert f.is_file
|
||||
|
||||
|
||||
def test_permissions_didnt_change(host):
|
||||
dirs = [
|
||||
"/etc",
|
||||
"/root",
|
||||
"/usr",
|
||||
"/var"
|
||||
]
|
||||
for file in dirs:
|
||||
f = host.file(file)
|
||||
assert f.exists
|
||||
assert f.is_directory
|
||||
assert f.user == "root"
|
||||
assert f.group == "root"
|
||||
|
||||
|
||||
def test_user(host):
|
||||
assert host.group("smokeping").exists
|
||||
assert "smokeping" in host.user("smokeping").groups
|
||||
assert host.user("smokeping").shell == "/usr/sbin/nologin"
|
||||
assert host.user("smokeping").home == "/"
|
||||
|
||||
|
||||
def test_service(host):
|
||||
s = host.service("smokeping_prober")
|
||||
# assert s.is_enabled
|
||||
assert s.is_running
|
||||
|
||||
|
||||
def test_protecthome_property(host):
|
||||
s = host.service("smokeping_prober")
|
||||
p = s.systemd_properties
|
||||
assert p.get("ProtectHome") == "yes"
|
||||
|
||||
|
||||
def test_socket(host):
|
||||
sockets = [
|
||||
"tcp://127.0.0.1:9374"
|
||||
]
|
||||
for socket in sockets:
|
||||
s = host.socket(socket)
|
||||
assert s.is_listening
|
8
roles/smokeping_prober/molecule/latest/converge.yml
Normal file
8
roles/smokeping_prober/molecule/latest/converge.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- name: Run role
|
||||
hosts: all
|
||||
any_errors_fatal: true
|
||||
roles:
|
||||
- prometheus.prometheus.smokeping_prober
|
||||
vars:
|
||||
smokeping_prober_version: latest
|
1
roles/smokeping_prober/molecule/latest/molecule.yml
Normal file
1
roles/smokeping_prober/molecule/latest/molecule.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
|
@ -0,0 +1,36 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import testinfra.utils.ansible_runner
|
||||
import pytest
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("files", [
|
||||
"/etc/systemd/system/smokeping_prober.service",
|
||||
"/usr/local/bin/smokeping_prober"
|
||||
])
|
||||
def test_files(host, files):
|
||||
f = host.file(files)
|
||||
assert f.exists
|
||||
assert f.is_file
|
||||
|
||||
|
||||
def test_service(host):
|
||||
s = host.service("smokeping_prober")
|
||||
# assert s.is_enabled
|
||||
assert s.is_running
|
||||
|
||||
|
||||
def test_protecthome_property(host):
|
||||
s = host.service("smokeping_prober")
|
||||
p = s.systemd_properties
|
||||
assert p.get("ProtectHome") == "yes"
|
||||
|
||||
|
||||
def test_socket(host):
|
||||
s = host.socket("tcp://0.0.0.0:9374")
|
||||
assert s.is_listening
|
30
roles/smokeping_prober/molecule/latest/tests/test_latest.py
Normal file
30
roles/smokeping_prober/molecule/latest/tests/test_latest.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import testinfra.utils.ansible_runner
|
||||
import pytest
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("files", [
|
||||
"/etc/systemd/system/smokeping_prober.service",
|
||||
"/usr/local/bin/smokeping_prober"
|
||||
])
|
||||
def test_files(host, files):
|
||||
f = host.file(files)
|
||||
assert f.exists
|
||||
assert f.is_file
|
||||
|
||||
|
||||
def test_service(host):
|
||||
s = host.service("smokeping_prober")
|
||||
# assert s.is_enabled
|
||||
assert s.is_running
|
||||
|
||||
|
||||
def test_socket(host):
|
||||
s = host.socket("tcp://0.0.0.0:9374")
|
||||
assert s.is_listening
|
52
roles/smokeping_prober/tasks/configure.yml
Normal file
52
roles/smokeping_prober/tasks/configure.yml
Normal file
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
- name: Copy the smokeping_prober systemd service file
|
||||
ansible.builtin.template:
|
||||
src: smokeping_prober.service.j2
|
||||
dest: /etc/systemd/system/smokeping_prober.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify: restart smokeping_prober
|
||||
|
||||
- name: Create smokeping_prober config directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ smokeping_prober_config_dir }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: u+rwX,g+rwX,o=rX
|
||||
|
||||
- name: Copy the smokeping_prober config file
|
||||
ansible.builtin.template:
|
||||
src: probes.yml.j2
|
||||
dest: "{{ smokeping_prober_config_dir }}/{{ smokeping_prober_config_file }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
no_log: "{{ 'false' if lookup('env', 'CI') else 'true' }}"
|
||||
notify: restart smokeping_prober
|
||||
|
||||
- name: Configure smokeping_prober web config
|
||||
when:
|
||||
( smokeping_prober_tls_server_config | length > 0 ) or
|
||||
( smokeping_prober_http_server_config | length > 0 ) or
|
||||
( smokeping_prober_basic_auth_users | length > 0 )
|
||||
block:
|
||||
- name: Copy the smokeping_prober web config file
|
||||
ansible.builtin.template:
|
||||
src: web_config.yaml.j2
|
||||
dest: "{{ smokeping_prober_config_dir }}/web_config.yaml"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify: restart smokeping_prober
|
||||
|
||||
- name: Allow smokeping_prober port in SELinux on RedHat OS family
|
||||
community.general.seport:
|
||||
ports: "{{ smokeping_prober_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"
|
69
roles/smokeping_prober/tasks/install.yml
Normal file
69
roles/smokeping_prober/tasks/install.yml
Normal file
|
@ -0,0 +1,69 @@
|
|||
---
|
||||
- name: Create the smokeping_prober group
|
||||
ansible.builtin.group:
|
||||
name: "{{ smokeping_prober_system_group }}"
|
||||
state: present
|
||||
system: true
|
||||
when: smokeping_prober_system_group != "root"
|
||||
|
||||
- name: Create the smokeping_prober user
|
||||
ansible.builtin.user:
|
||||
name: "{{ smokeping_prober_system_user }}"
|
||||
groups: "{{ smokeping_prober_system_group }}"
|
||||
append: true
|
||||
shell: /usr/sbin/nologin
|
||||
system: true
|
||||
create_home: false
|
||||
home: /
|
||||
when: smokeping_prober_system_user != "root"
|
||||
|
||||
- name: Discover latest version
|
||||
when:
|
||||
- smokeping_prober_binary_local_dir | length == 0
|
||||
- not smokeping_prober_skip_install
|
||||
block:
|
||||
|
||||
- name: Download smokeping_prober binary to local folder
|
||||
become: false
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ smokeping_prober_binary_url }}"
|
||||
dest: "/tmp/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
checksum: "sha256:{{ __smokeping_prober_checksum }}"
|
||||
mode: '0644'
|
||||
register: _download_binary
|
||||
until: _download_binary is succeeded
|
||||
retries: 5
|
||||
delay: 2
|
||||
delegate_to: localhost
|
||||
check_mode: false
|
||||
|
||||
- name: Unpack smokeping_prober binary
|
||||
become: false
|
||||
ansible.builtin.unarchive:
|
||||
src: "/tmp/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
dest: "/tmp"
|
||||
creates: "/tmp/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}/smokeping_prober"
|
||||
delegate_to: localhost
|
||||
check_mode: false
|
||||
|
||||
- name: Propagate smokeping_prober binaries
|
||||
ansible.builtin.copy:
|
||||
src: "/tmp/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}/smokeping_prober"
|
||||
dest: "{{ smokeping_prober_binary_install_dir }}/smokeping_prober"
|
||||
mode: 0755
|
||||
owner: root
|
||||
group: root
|
||||
notify: restart smokeping_prober
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Propagate locally distributed smokeping_prober binary
|
||||
ansible.builtin.copy:
|
||||
src: "{{ smokeping_prober_binary_local_dir }}/smokeping_prober"
|
||||
dest: "{{ smokeping_prober_binary_install_dir }}/smokeping_prober"
|
||||
mode: 0755
|
||||
owner: root
|
||||
group: root
|
||||
when:
|
||||
- smokeping_prober_binary_local_dir | length > 0
|
||||
- not smokeping_prober_skip_install
|
||||
notify: restart smokeping_prober
|
63
roles/smokeping_prober/tasks/main.yml
Normal file
63
roles/smokeping_prober/tasks/main.yml
Normal file
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
- name: Preflight
|
||||
ansible.builtin.include_tasks:
|
||||
file: preflight.yml
|
||||
apply:
|
||||
tags:
|
||||
- smokeping_prober_install
|
||||
- smokeping_prober_configure
|
||||
- smokeping_prober_run
|
||||
tags:
|
||||
- smokeping_prober_install
|
||||
- smokeping_prober_configure
|
||||
- smokeping_prober_run
|
||||
|
||||
- name: Install
|
||||
ansible.builtin.include_tasks:
|
||||
file: install.yml
|
||||
apply:
|
||||
become: true
|
||||
tags:
|
||||
- smokeping_prober_install
|
||||
when:
|
||||
( not __smokeping_prober_is_installed.stat.exists ) or
|
||||
( (__smokeping_prober_current_version_output.stderr_lines | length > 0)
|
||||
and (__smokeping_prober_current_version_output.stderr_lines[0].split(" ")[2] != smokeping_prober_version) ) or
|
||||
( (__smokeping_prober_current_version_output.stdout_lines | length > 0)
|
||||
and (__smokeping_prober_current_version_output.stdout_lines[0].split(" ")[2] != smokeping_prober_version) ) or
|
||||
( smokeping_prober_binary_local_dir | length > 0 )
|
||||
tags:
|
||||
- smokeping_prober_install
|
||||
|
||||
- name: SELinux
|
||||
ansible.builtin.include_tasks:
|
||||
file: selinux.yml
|
||||
apply:
|
||||
become: true
|
||||
tags:
|
||||
- smokeping_prober_configure
|
||||
when: ansible_selinux.status == "enabled"
|
||||
tags:
|
||||
- smokeping_prober_configure
|
||||
|
||||
- name: Configure
|
||||
ansible.builtin.include_tasks:
|
||||
file: configure.yml
|
||||
apply:
|
||||
become: true
|
||||
tags:
|
||||
- smokeping_prober_configure
|
||||
tags:
|
||||
- smokeping_prober_configure
|
||||
|
||||
- name: Ensure Smokeping Prober is enabled on boot
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
name: smokeping_prober
|
||||
enabled: true
|
||||
state: started
|
||||
when:
|
||||
- not ansible_check_mode
|
||||
tags:
|
||||
- smokeping_prober_run
|
99
roles/smokeping_prober/tasks/preflight.yml
Normal file
99
roles/smokeping_prober/tasks/preflight.yml
Normal file
|
@ -0,0 +1,99 @@
|
|||
---
|
||||
- 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: Naive assertion of proper listen address
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "':' in smokeping_prober_web_listen_address"
|
||||
|
||||
- name: Assert that TLS config is correct
|
||||
when: smokeping_prober_tls_server_config | length > 0
|
||||
block:
|
||||
- name: Assert that TLS key and cert path are set
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "smokeping_prober_tls_server_config.cert_file is defined"
|
||||
- "smokeping_prober_tls_server_config.key_file is defined"
|
||||
|
||||
- name: Check existence of TLS cert file
|
||||
ansible.builtin.stat:
|
||||
path: "{{ smokeping_prober_tls_server_config.cert_file }}"
|
||||
register: __smokeping_prober_cert_file
|
||||
|
||||
- name: Check existence of TLS key file
|
||||
ansible.builtin.stat:
|
||||
path: "{{ smokeping_prober_tls_server_config.key_file }}"
|
||||
register: __smokeping_prober_key_file
|
||||
|
||||
- name: Assert that TLS key and cert are present
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "{{ __smokeping_prober_cert_file.stat.exists }}"
|
||||
- "{{ __smokeping_prober_key_file.stat.exists }}"
|
||||
|
||||
- name: Check if smokeping_prober is installed
|
||||
ansible.builtin.stat:
|
||||
path: "{{ smokeping_prober_binary_install_dir }}/smokeping_prober"
|
||||
register: __smokeping_prober_is_installed
|
||||
check_mode: false
|
||||
tags:
|
||||
- smokeping_prober_install
|
||||
|
||||
- name: Gather currently installed smokeping_prober version (if any)
|
||||
ansible.builtin.command: "{{ smokeping_prober_binary_install_dir }}/smokeping_prober --version"
|
||||
changed_when: false
|
||||
register: __smokeping_prober_current_version_output
|
||||
check_mode: false
|
||||
when: __smokeping_prober_is_installed.stat.exists
|
||||
tags:
|
||||
- smokeping_prober_install
|
||||
|
||||
- name: Discover latest version
|
||||
ansible.builtin.set_fact:
|
||||
smokeping_prober_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _smokeping_prober_repo }}/releases/latest', headers=_github_api_headers,
|
||||
split_lines=False) | from_json).get('tag_name') | replace('v', '') }}"
|
||||
run_once: true
|
||||
until: smokeping_prober_version is version('0.0.0', '>=')
|
||||
retries: 10
|
||||
when:
|
||||
- smokeping_prober_version == "latest"
|
||||
- smokeping_prober_binary_local_dir | length == 0
|
||||
- not smokeping_prober_skip_install
|
||||
|
||||
- name: Get smokeping_prober binary checksum
|
||||
when:
|
||||
- smokeping_prober_binary_local_dir | length == 0
|
||||
- not smokeping_prober_skip_install
|
||||
block:
|
||||
- name: Get checksum list from github
|
||||
ansible.builtin.set_fact:
|
||||
__smokeping_prober_checksums: "{{ lookup('url', smokeping_prober_checksums_url, headers=_github_api_headers, wantlist=True) | list }}"
|
||||
run_once: true
|
||||
until: __smokeping_prober_checksums is search('linux-' + go_arch + '.tar.gz')
|
||||
retries: 10
|
||||
|
||||
- name: "Get checksum for {{ go_arch }}"
|
||||
ansible.builtin.set_fact:
|
||||
__smokeping_prober_checksum: "{{ item.split(' ')[0] }}"
|
||||
with_items: "{{ __smokeping_prober_checksums }}"
|
||||
when:
|
||||
- "('linux-' + go_arch + '.tar.gz') in item"
|
23
roles/smokeping_prober/tasks/selinux.yml
Normal file
23
roles/smokeping_prober/tasks/selinux.yml
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
- 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"
|
||||
|
||||
- name: Install selinux python packages [clearlinux]
|
||||
ansible.builtin.package:
|
||||
name: sysadmin-basic
|
||||
state: present
|
||||
register: _install_selinux_packages
|
||||
until: _install_selinux_packages is success
|
||||
retries: 5
|
||||
delay: 2
|
||||
when:
|
||||
- ansible_distribution | lower == "clearlinux"
|
4
roles/smokeping_prober/templates/probes.yml.j2
Normal file
4
roles/smokeping_prober/templates/probes.yml.j2
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
{{ ansible_managed | comment }}
|
||||
targets:
|
||||
{{ smokeping_prober_targets | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
|
42
roles/smokeping_prober/templates/smokeping_prober.service.j2
Normal file
42
roles/smokeping_prober/templates/smokeping_prober.service.j2
Normal file
|
@ -0,0 +1,42 @@
|
|||
{{ ansible_managed | comment }}
|
||||
[Unit]
|
||||
Description=Smokeping Prober
|
||||
After=network-online.target
|
||||
StartLimitInterval=0
|
||||
StartLimitIntervalSec=0
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ smokeping_prober_system_user }}
|
||||
Group={{ smokeping_prober_system_group }}
|
||||
PermissionsStartOnly=true
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
ExecStart={{ smokeping_prober_binary_install_dir }}/smokeping_prober \
|
||||
--config.file={{ smokeping_prober_config_dir }}//{{ smokeping_prober_config_file }} \
|
||||
--web.listen-address={{ smokeping_prober_web_listen_address }}
|
||||
|
||||
SyslogIdentifier=smokeping_prober
|
||||
KillMode=process
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
LockPersonality=true
|
||||
NoNewPrivileges=true
|
||||
MemoryDenyWriteExecute=true
|
||||
PrivateTmp=true
|
||||
ProtectHome=true
|
||||
RemoveIPC=true
|
||||
RestrictSUIDSGID=true
|
||||
|
||||
AmbientCapabilities=CAP_NET_RAW
|
||||
{% if (ansible_facts.packages.systemd | first).version is version('232', '>=') %}
|
||||
ProtectControlGroups=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelTunables=yes
|
||||
ProtectSystem=strict
|
||||
{% else %}
|
||||
ProtectSystem=full
|
||||
{% endif %}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
18
roles/smokeping_prober/templates/web_config.yaml.j2
Normal file
18
roles/smokeping_prober/templates/web_config.yaml.j2
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
{{ ansible_managed | comment }}
|
||||
{% if smokeping_prober_tls_server_config | length > 0 %}
|
||||
tls_server_config:
|
||||
{{ smokeping_prober_tls_server_config | to_nice_yaml | indent(2, true) }}
|
||||
{% endif %}
|
||||
|
||||
{% if smokeping_prober_http_server_config | length > 0 %}
|
||||
http_server_config:
|
||||
{{ smokeping_prober_http_server_config | to_nice_yaml | indent(2, true) }}
|
||||
{% endif %}
|
||||
|
||||
{% if smokeping_prober_basic_auth_users | length > 0 %}
|
||||
basic_auth_users:
|
||||
{% for k, v in smokeping_prober_basic_auth_users.items() %}
|
||||
{{ k }}: {{ v | string | password_hash('bcrypt', ('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' | shuffle(seed=inventory_hostname) | join)[:22], rounds=9) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
1
roles/smokeping_prober/test-requirements.txt
Normal file
1
roles/smokeping_prober/test-requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
bcrypt
|
11
roles/smokeping_prober/vars/main.yml
Normal file
11
roles/smokeping_prober/vars/main.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
go_arch_map:
|
||||
i386: '386'
|
||||
x86_64: 'amd64'
|
||||
aarch64: 'arm64'
|
||||
armv7l: 'armv7'
|
||||
armv6l: 'armv6'
|
||||
|
||||
go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
|
||||
_smokeping_prober_repo: "superq/smokeping_prober"
|
||||
_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}"
|
4
tests/integration/targets/molecule-smokeping_prober-alternative/runme.sh
Executable file
4
tests/integration/targets/molecule-smokeping_prober-alternative/runme.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+")
|
||||
source "$collection_root/tests/integration/molecule.sh"
|
4
tests/integration/targets/molecule-smokeping_prober-default/runme.sh
Executable file
4
tests/integration/targets/molecule-smokeping_prober-default/runme.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+")
|
||||
source "$collection_root/tests/integration/molecule.sh"
|
4
tests/integration/targets/molecule-smokeping_prober-latest/runme.sh
Executable file
4
tests/integration/targets/molecule-smokeping_prober-latest/runme.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+")
|
||||
source "$collection_root/tests/integration/molecule.sh"
|
Loading…
Reference in a new issue