Skip to content

Commit 15e6135

Browse files
committed
Fixes #353 - Add health check command
Add a new foremanctl health command that verifies the state of all Foreman services after installation or during troubleshooting. Checks performed: - Core services running (foreman, httpd, redis, postgresql) - Dynflow workers running (orchestrator, worker, worker-hosts-queue) - Pulp services running (pulp-api, pulp-content) - Candlepin service running - Foreman API responding (GET /api/v2/ping) - Foreman tasks status (via Katello ping response) Reports a summary of all failures and exits non-zero if any check fails, making it suitable for scripting and CI use.
1 parent 5efa47a commit 15e6135

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

src/filter_plugins/foremanctl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def available_foreman_proxy_plugins(_value):
9494
return compact_list(plugins)
9595

9696

97+
def has_content_features(features):
98+
return any(f.startswith('content/') for f in features)
99+
97100
class FilterModule(object):
98101
'''foremanctl filters'''
99102

@@ -106,4 +109,5 @@ def filters(self):
106109
'available_foreman_proxy_plugins': available_foreman_proxy_plugins,
107110
'list_all_features': list_all_features,
108111
'invalid_features': invalid_features,
112+
'has_content_features': has_content_features,
109113
}

src/playbooks/health/health.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- name: Run Foreman health checks
3+
hosts: quadlet
4+
become: true
5+
gather_facts: true
6+
vars_files:
7+
- "../../vars/defaults.yml"
8+
- "../../vars/base.yaml"
9+
tasks:
10+
- name: Execute health checks
11+
ansible.builtin.include_role:
12+
name: checks
13+
tasks_from: execute_check
14+
loop:
15+
- check_services
16+
- check_foreman_api
17+
- name: Report status of health checks
18+
ansible.builtin.fail:
19+
msg: "{{ checks_results }}"
20+
when:
21+
- checks_results|default([])|length > 0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
help: |
3+
Run health checks on Foreman services
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: Check Foreman API responds
3+
ansible.builtin.uri:
4+
url: "{{ foreman_url }}/api/v2/ping"
5+
validate_certs: false
6+
status_code: 200
7+
timeout: 10
8+
register: check_foreman_api_ping
9+
10+
- name: Check Foreman tasks status
11+
ansible.builtin.assert:
12+
that:
13+
- check_foreman_api_ping.json.results.katello.services.foreman_tasks.status == 'ok'
14+
fail_msg: "Foreman tasks status: {{ check_foreman_api_ping.json.results.katello.services.foreman_tasks.status | default('unknown') }}"
15+
success_msg: "Foreman tasks status: ok"
16+
when:
17+
- enabled_features | has_content_features
18+
- check_foreman_api_ping.json.results.katello is defined
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
- name: Gather service facts
3+
ansible.builtin.service_facts:
4+
5+
- name: Check core services are running
6+
ansible.builtin.assert:
7+
that:
8+
- "ansible_facts.services[item + '.service'] is defined"
9+
- "ansible_facts.services[item + '.service']['state'] == 'running'"
10+
fail_msg: "Service {{ item }} is not running"
11+
success_msg: "Service {{ item }} is running"
12+
loop:
13+
- foreman
14+
- httpd
15+
- redis
16+
- postgresql
17+
18+
- name: Check dynflow services are running
19+
ansible.builtin.assert:
20+
that:
21+
- "ansible_facts.services[item + '.service'] is defined"
22+
- "ansible_facts.services[item + '.service']['state'] == 'running'"
23+
fail_msg: "Service {{ item }} is not running"
24+
success_msg: "Service {{ item }} is running"
25+
loop:
26+
- dynflow-sidekiq@orchestrator
27+
- dynflow-sidekiq@worker
28+
- dynflow-sidekiq@worker-hosts-queue
29+
30+
- name: Check Pulp services are running
31+
ansible.builtin.assert:
32+
that:
33+
- "ansible_facts.services[item + '.service'] is defined"
34+
- "ansible_facts.services[item + '.service']['state'] == 'running'"
35+
fail_msg: "Service {{ item }} is not running"
36+
success_msg: "Service {{ item }} is running"
37+
loop:
38+
- pulp-api
39+
- pulp-content
40+
when: enabled_features | has_content_features
41+
42+
- name: Check Candlepin service is running
43+
ansible.builtin.assert:
44+
that:
45+
- "ansible_facts.services['candlepin.service'] is defined"
46+
- "ansible_facts.services['candlepin.service']['state'] == 'running'"
47+
fail_msg: "Service candlepin is not running"
48+
success_msg: "Service candlepin is running"
49+
when: enabled_features | has_content_features

0 commit comments

Comments
 (0)