Skip to content
This repository was archived by the owner on Apr 15, 2023. It is now read-only.

Commit 26ce333

Browse files
authored
Merge pull request #31 from stdevel/feat-monitoring-30
Add monitoring support
2 parents 0b51d20 + 4dddb35 commit 26ce333

File tree

13 files changed

+240
-18
lines changed

13 files changed

+240
-18
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This role prepares, installs and configures [Uyuni](https://uyuni-project.org) a
88

99
Make sure to install the `jmespath` and `xml` Python modules.
1010

11-
The system needs access to the internet. Also, you will need an openSUSE Leap or SUSE Linux Enterprise Server 15.1+ installation.
11+
The system needs access to the internet. Also, you will need an openSUSE Leap 15.3 or SUSE Linux Enterprise Server 15.2+ installation.
1212

1313
## Role Variables
1414

@@ -51,9 +51,11 @@ The system needs access to the internet. Also, you will need an openSUSE Leap or
5151
| `uyuni_defs_setup` | `false` | Flag whether errata for Debian should be generated via [DEFS](https://defs.steve-meier.de/) |
5252
| `uyuni_defs_setup_cronjob` | `false` | Flag whether DEFS cronjob should be generated |
5353
| `uyuni_cefs_path` | `/opt/errata-import` | Path to install CEFS and the wrapper script to |
54-
| `uyuni_channels`| *empty* | Common channels to synchronize (*e.g. ``centos7`` and ``epel7``*) |
54+
| `uyuni_channels`| *empty* | Common channels to synchronize (*e.g. `centos7` and `epel7`*) |
5555
| `uyuni_sync_channels` | `false` | Flag whether created channels should be synced |
5656
| `uyuni_bootstrap_repos` | `false` | Flag whether Salt bootstrap repositories should be created |
57+
| `uyuni_enable_monitoring` | `false` | Flag whether integrated monitoring stack should be enabled |
58+
| `uyuni_install_monitoring_formulas` | `false` | Flag whether monitoring Salt Formulas should be installed |
5759

5860
When supplying channels to create in `channels`, ensure passing a list with dicts like this:
5961

defaults/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ uyuni_firewall_config: true
8787
uyuni_firewall_default_zone: internal
8888
uyuni_firewall_services:
8989
- suse-manager-server
90+
uyuni_firewall_services_monitoring:
91+
- prometheus
9092

9193
# content settings
9294
uyuni_cefs_setup: false
@@ -105,3 +107,17 @@ uyuni_channels: []
105107
# - {"name": "centos7-updates", "arch": "x86_64"}
106108
uyuni_sync_channels: false
107109
uyuni_bootstrap_repos: false
110+
111+
# monitoring settings
112+
uyuni_enable_monitoring: false
113+
uyuni_monitoring_packages:
114+
- golang-github-prometheus-node_exporter
115+
- golang-github-wrouesnel-postgres_exporter
116+
- prometheus-jmx_exporter
117+
- golang-github-lusitaniae-apache_exporter
118+
- prometheus-jmx_exporter-tomcat
119+
uyuni_install_monitoring_formulas: false
120+
uyuni_monitoring_formulas_packages:
121+
- grafana-formula
122+
- prometheus-formula
123+
- prometheus-exporters-formula

handlers/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
---
2-
# handlers file for ansible-uyuni
2+
- name: Restart Uyuni
3+
command: spacewalk-service restart
4+
become: true

molecule/default/converge.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@
2020
uyuni_channels:
2121
- {"name": "centos7", "arch": "x86_64"}
2222
- {"name": "centos7-updates", "arch": "x86_64"}
23-
# uyuni_release: '2021.12'
23+
uyuni_enable_monitoring: true
24+
uyuni_install_monitoring_formulas: true
25+
# Installation in 2022.02 is currently fragile
26+
# see also: https://github.com/uyuni-project/uyuni/issues/5009
27+
uyuni_release: '2022.01'

molecule/default/tests/test_default.py

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ def test_lvm(host):
1515
test if storage was set-up correctly
1616
"""
1717
# get variables from file
18-
ansible_vars = host.ansible("include_vars", "file=main.yml")
18+
ansible_vars = host.ansible(
19+
"include_vars",
20+
"file=molecule/default/vars/main.yml"
21+
)
1922
if ansible_vars["ansible_facts"]["uyuni_use_lvm"]:
2023
# check file systems
2124
for filesys in ansible_vars["ansible_facts"]["uyuni_filesystems"]:
@@ -30,7 +33,10 @@ def test_packages(host):
3033
check if packages are installed
3134
"""
3235
# get variables from file
33-
ansible_vars = host.ansible("include_vars", "file=main.yml")
36+
ansible_vars = host.ansible(
37+
"include_vars",
38+
"file=molecule/default/vars/main.yml"
39+
)
3440
# check dependencies and Uyuni packages
3541
for pkg in ansible_vars["ansible_facts"]["uyuni_core_packages"] + \
3642
ansible_vars["ansible_facts"]["uyuni_packages"]:
@@ -61,7 +67,10 @@ def test_firewall(host):
6167
check if firewall is configured properly
6268
"""
6369
# get variables from file
64-
ansible_vars = host.ansible("include_vars", "file=main.yml")
70+
ansible_vars = host.ansible(
71+
"include_vars",
72+
"file=molecule/default/vars/main.yml"
73+
)
6574
# check if services are enabled
6675
if ansible_vars["ansible_facts"]["uyuni_firewall_config"]:
6776
with host.sudo():
@@ -75,7 +84,10 @@ def test_org(host):
7584
check if organization is accessible
7685
"""
7786
# get variables from file
78-
ansible_vars = host.ansible("include_vars", "file=main.yml")
87+
ansible_vars = host.ansible(
88+
"include_vars",
89+
"file=molecule/default/vars/main.yml"
90+
)
7991
# check if organization exists
8092
cmd_org = host.run(
8193
"spacecmd -q -u %s -p %s org_list",
@@ -90,7 +102,10 @@ def test_errata(host):
90102
check if CEFS/DEFS are installed properly
91103
"""
92104
# get variables from file
93-
ansible_vars = host.ansible("include_vars", "file=main.yml")
105+
ansible_vars = host.ansible(
106+
"include_vars",
107+
"file=molecule/default/vars/main.yml"
108+
)
94109
if ansible_vars["ansible_facts"]["uyuni_cefs_setup"]:
95110
# check package dependencies
96111
for pkg in ansible_vars["ansible_facts"]["uyuni_cefs_packages"]:
@@ -111,7 +126,10 @@ def test_channels(host):
111126
check if supplied channels were created
112127
"""
113128
# get variables from file
114-
ansible_vars = host.ansible("include_vars", "file=main.yml")
129+
ansible_vars = host.ansible(
130+
"include_vars",
131+
"file=molecule/default/vars/main.yml"
132+
)
115133
# get spacewalk-common-channels definitions from client
116134
with host.sudo():
117135
definition_file = host.file(
@@ -137,3 +155,44 @@ def test_channels(host):
137155
)
138156
# ensure that repository exists
139157
assert repo_name in cmd_channels.stdout.strip().split("\n")
158+
159+
160+
def test_monitoring_packages(host):
161+
"""
162+
check if monitoring packages have been installed
163+
"""
164+
# get variables from file
165+
ansible_vars = host.ansible(
166+
"include_vars",
167+
"file=molecule/default/vars/main.yml"
168+
)
169+
# set packages
170+
pkgs = []
171+
if ansible_vars["ansible_facts"]["uyuni_enable_monitoring"]:
172+
pkgs = pkgs + ansible_vars["ansible_facts"]["uyuni_monitoring_packages"]
173+
if ansible_vars["ansible_facts"]["uyuni_install_monitoring_formulas"]:
174+
pkgs = pkgs + ansible_vars["ansible_facts"]["uyuni_monitoring_formulas_packages"]
175+
# check packages
176+
for pkg in pkgs:
177+
print(pkg)
178+
assert host.package(pkg).is_installed
179+
180+
181+
def test_monitoring_enabled(host):
182+
"""
183+
check if monitoring is enabled
184+
"""
185+
# get variables from file
186+
ansible_vars = host.ansible(
187+
"include_vars",
188+
"file=molecule/default/vars/main.yml"
189+
)
190+
# check configuration
191+
if ansible_vars["ansible_facts"]["uyuni_enable_monitoring"]:
192+
with host.sudo():
193+
rhn_cfg = host.file("/etc/rhn/rhn.conf")
194+
assert rhn_cfg.contains("prometheus_monitoring_enabled")
195+
# check status
196+
with host.sudo():
197+
mon_status = host.run("mgr-monitoring-ctl status")
198+
assert "error" not in mon_status.stdout.strip().lower()

molecule/default/vars/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,17 @@ uyuni_channels:
4141
arch: x86_64
4242
- name: centos7-updates
4343
arch: x86_64
44+
45+
# monitoring settings
46+
uyuni_enable_monitoring: true
47+
uyuni_monitoring_packages:
48+
- golang-github-prometheus-node_exporter
49+
- golang-github-wrouesnel-postgres_exporter
50+
- prometheus-jmx_exporter
51+
- golang-github-lusitaniae-apache_exporter
52+
- prometheus-jmx_exporter-tomcat
53+
uyuni_install_monitoring_formulas: true
54+
uyuni_monitoring_formulas_packages:
55+
- grafana-formula
56+
- prometheus-formula
57+
- prometheus-exporters-formula

molecule/suma/converge.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
uyuni_channels:
1414
- {"name": "centos7", "arch": "x86_64"}
1515
- {"name": "centos7-updates", "arch": "x86_64"}
16+
uyuni_enable_monitoring: true
17+
uyuni_install_monitoring_formulas: true

molecule/suma/tests/test_default.py

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ def test_lvm(host):
1515
test if storage was set-up correctly
1616
"""
1717
# get variables from file
18-
ansible_vars = host.ansible("include_vars", "file=main.yml")
18+
ansible_vars = host.ansible(
19+
"include_vars",
20+
"file=molecule/default/vars/main.yml"
21+
)
1922
if ansible_vars["ansible_facts"]["uyuni_use_lvm"]:
2023
# check file systems
2124
for filesys in ansible_vars["ansible_facts"]["uyuni_filesystems"]:
@@ -30,7 +33,10 @@ def test_packages(host):
3033
check if packages are installed
3134
"""
3235
# get variables from file
33-
ansible_vars = host.ansible("include_vars", "file=main.yml")
36+
ansible_vars = host.ansible(
37+
"include_vars",
38+
"file=molecule/default/vars/main.yml"
39+
)
3440
# check dependencies and Uyuni packages
3541
for pkg in ansible_vars["ansible_facts"]["uyuni_core_packages"] + \
3642
ansible_vars["ansible_facts"]["uyuni_packages"]:
@@ -61,7 +67,10 @@ def test_firewall(host):
6167
check if firewall is configured properly
6268
"""
6369
# get variables from file
64-
ansible_vars = host.ansible("include_vars", "file=main.yml")
70+
ansible_vars = host.ansible(
71+
"include_vars",
72+
"file=molecule/default/vars/main.yml"
73+
)
6574
# check if services are enabled
6675
if ansible_vars["ansible_facts"]["uyuni_firewall_config"]:
6776
with host.sudo():
@@ -75,7 +84,10 @@ def test_org(host):
7584
check if organization is accessible
7685
"""
7786
# get variables from file
78-
ansible_vars = host.ansible("include_vars", "file=main.yml")
87+
ansible_vars = host.ansible(
88+
"include_vars",
89+
"file=molecule/default/vars/main.yml"
90+
)
7991
# check if organization exists
8092
cmd_org = host.run(
8193
"spacecmd -q -u %s -p %s org_list",
@@ -90,7 +102,10 @@ def test_errata(host):
90102
check if CEFS/DEFS are installed properly
91103
"""
92104
# get variables from file
93-
ansible_vars = host.ansible("include_vars", "file=main.yml")
105+
ansible_vars = host.ansible(
106+
"include_vars",
107+
"file=molecule/default/vars/main.yml"
108+
)
94109
if ansible_vars["ansible_facts"]["uyuni_cefs_setup"]:
95110
# check package dependencies
96111
for pkg in ansible_vars["ansible_facts"]["uyuni_cefs_packages"]:
@@ -111,7 +126,10 @@ def test_channels(host):
111126
check if supplied channels were created
112127
"""
113128
# get variables from file
114-
ansible_vars = host.ansible("include_vars", "file=main.yml")
129+
ansible_vars = host.ansible(
130+
"include_vars",
131+
"file=molecule/default/vars/main.yml"
132+
)
115133
# get spacewalk-common-channels definitions from client
116134
with host.sudo():
117135
definition_file = host.file(
@@ -137,3 +155,44 @@ def test_channels(host):
137155
)
138156
# ensure that repository exists
139157
assert repo_name in cmd_channels.stdout.strip().split("\n")
158+
159+
160+
def test_monitoring_packages(host):
161+
"""
162+
check if monitoring packages have been installed
163+
"""
164+
# get variables from file
165+
ansible_vars = host.ansible(
166+
"include_vars",
167+
"file=molecule/default/vars/main.yml"
168+
)
169+
# set packages
170+
pkgs = []
171+
if ansible_vars["ansible_facts"]["uyuni_enable_monitoring"]:
172+
pkgs = pkgs + ansible_vars["ansible_facts"]["uyuni_monitoring_packages"]
173+
if ansible_vars["ansible_facts"]["uyuni_install_monitoring_formulas"]:
174+
pkgs = pkgs + ansible_vars["ansible_facts"]["uyuni_monitoring_formulas_packages"]
175+
# check packages
176+
for pkg in pkgs:
177+
print(pkg)
178+
assert host.package(pkg).is_installed
179+
180+
181+
def test_monitoring_enabled(host):
182+
"""
183+
check if monitoring is enabled
184+
"""
185+
# get variables from file
186+
ansible_vars = host.ansible(
187+
"include_vars",
188+
"file=molecule/default/vars/main.yml"
189+
)
190+
# check configuration
191+
if ansible_vars["ansible_facts"]["uyuni_enable_monitoring"]:
192+
with host.sudo():
193+
rhn_cfg = host.file("/etc/rhn/rhn.conf")
194+
assert rhn_cfg.contains("prometheus_monitoring_enabled")
195+
# check status
196+
with host.sudo():
197+
mon_status = host.run("mgr-monitoring-ctl status")
198+
assert "error" not in mon_status.stdout.strip().lower()

molecule/suma/vars/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,17 @@ uyuni_channels:
4141
arch: x86_64
4242
- name: centos7-updates
4343
arch: x86_64
44+
45+
# monitoring settings
46+
uyuni_enable_monitoring: true
47+
uyuni_monitoring_packages:
48+
- golang-github-prometheus-node_exporter
49+
- golang-github-wrouesnel-postgres_exporter
50+
- prometheus-jmx_exporter
51+
- golang-github-lusitaniae-apache_exporter
52+
- prometheus-jmx_exporter-tomcat
53+
uyuni_install_monitoring_formulas: true
54+
uyuni_monitoring_formulas_packages:
55+
- grafana-formula
56+
- prometheus-formula
57+
- prometheus-exporters-formula

tasks/content.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
command: spacewalk-common-channels -u {{ uyuni_org_login }} -p {{ uyuni_org_password }} -a {{ item.arch }} {{ item.name }}
5555
loop: "{{ uyuni_channels }}"
5656
register: create_result
57-
changed_when: '"already in use" not in create_result.stderr | lower'
57+
changed_when:
58+
- '"exists" not in create_result.stdout | lower'
59+
- '"already in use" not in create_result.stderr | lower'
5860
become: true
5961
when: uyuni_channels | length > 0
6062

0 commit comments

Comments
 (0)