Skip to content

Commit 4da5a13

Browse files
martinpittrichm
authored andcommitted
fix: Skip runtime service operations for non-booted hosts
When running the role against a buildah or non-system podman host (e.g. as part of creating a bootc image), services can't actually start. So skip these runtime operations and just enable the services on-disk.
1 parent e876784 commit 4da5a13

File tree

12 files changed

+97
-11
lines changed

12 files changed

+97
-11
lines changed

roles/elasticsearch/tasks/main.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,23 @@
8181
- elasticsearch_metrics_provider == 'pcp'
8282
- elasticsearch_export_metrics | d(false) | bool
8383

84+
- name: Determine if host is booted
85+
# noqa command-instead-of-module
86+
command: systemctl is-system-running
87+
register: __system_running
88+
changed_when: false
89+
check_mode: false
90+
failed_when: false
91+
92+
- name: Require installed systemd
93+
fail:
94+
msg: "Error: This role requires systemd to be installed."
95+
when: '"No such file or directory" in __system_running.msg | d("")'
96+
8497
- name: Ensure PCP Elasticsearch export is running and enabled on boot
8598
service:
8699
name: pcp2elasticsearch
87-
state: started
100+
state: "{{ 'started' if __system_running.stdout != 'offline' else omit }}"
88101
enabled: true
89102
ignore_errors: true # noqa ignore-errors
90103
# Elasticsearch server may be running remotely or presently down

roles/grafana/handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
service:
66
name: grafana-server
77
state: restarted
8+
when: __grafana_is_booted | bool

roles/grafana/tasks/main.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424
set_fact:
2525
__ansible_pcp_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
2626

27+
- name: Determine if host is booted
28+
# noqa command-instead-of-module
29+
command: systemctl is-system-running
30+
register: __is_system_running
31+
changed_when: false
32+
check_mode: false
33+
failed_when: false
34+
35+
- name: Require installed systemd
36+
fail:
37+
msg: "Error: This role requires systemd to be installed."
38+
when: '"No such file or directory" in __is_system_running.msg | d("")'
39+
40+
- name: Set flag to indicate that systemd runtime operations are available
41+
set_fact:
42+
__grafana_is_booted: "{{ __is_system_running.stdout != 'offline' }}"
43+
2744
- name: Install Grafana packages
2845
package:
2946
name: "{{ __grafana_packages + __grafana_packages_extra }}"
@@ -72,7 +89,7 @@
7289
- name: Ensure graphing service is running and enabled on boot
7390
service:
7491
name: grafana-server
75-
state: started
92+
state: "{{ 'started' if __grafana_is_booted else omit }}"
7693
enabled: true
7794

7895
# yamllint disable rule:line-length

roles/keyserver/handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
service:
66
name: "{{ __keyserver_name }}"
77
state: restarted
8+
when: __keyserver_is_booted | bool

roles/keyserver/tasks/main.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@
2828
set_fact:
2929
__ansible_pcp_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
3030

31+
- name: Determine if host is booted
32+
# noqa command-instead-of-module
33+
command: systemctl is-system-running
34+
register: __is_system_running
35+
changed_when: false
36+
check_mode: false
37+
failed_when: false
38+
39+
- name: Require installed systemd
40+
fail:
41+
msg: "Error: This role requires systemd to be installed."
42+
when: '"No such file or directory" in __is_system_running.msg | d("")'
43+
44+
- name: Set flag to indicate that systemd runtime operations are available
45+
set_fact:
46+
__keyserver_is_booted: "{{ __is_system_running.stdout != 'offline' }}"
47+
3148
- name: Install key server packages
3249
package:
3350
name: "{{ __keyserver_packages + __keyserver_packages_extra }}"
@@ -68,5 +85,5 @@
6885
- name: Ensure key server service is running and enabled on boot
6986
service:
7087
name: "{{ __keyserver_name }}"
71-
state: started
88+
state: "{{ 'started' if __keyserver_is_booted else omit }}"
7289
enabled: true

roles/pcp/handlers/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
service:
66
name: pmcd
77
state: restarted
8+
when: __pcp_is_booted | bool
89

910
- name: Restart pmie
1011
service:
1112
name: pmie
1213
state: restarted
14+
when: __pcp_is_booted | bool
1315

1416
- name: Restart pmproxy
1517
service:
1618
name: pmproxy
1719
state: restarted
20+
when: __pcp_is_booted | bool
1821

1922
- name: Restart pmlogger
2023
service:
2124
name: pmlogger
2225
state: restarted
26+
when: __pcp_is_booted | bool

roles/pcp/tasks/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
set_fact:
2525
__ansible_pcp_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
2626

27+
- name: Determine if host is booted
28+
when: __pcp_is_booted is not defined
29+
block:
30+
- name: Run systemctl
31+
# noqa command-instead-of-module
32+
command: systemctl is-system-running
33+
register: __is_system_running
34+
changed_when: false
35+
check_mode: false
36+
failed_when: false
37+
38+
- name: Require installed systemd
39+
fail:
40+
msg: "Error: This role requires systemd to be installed."
41+
when: '"No such file or directory" in __is_system_running.msg | d("")'
42+
43+
- name: Set flag to indicate that systemd runtime operations are available
44+
set_fact:
45+
__pcp_is_booted: "{{ __is_system_running.stdout != 'offline' }}"
46+
2747
- name: Install Performance Co-Pilot packages
2848
package:
2949
name: "{{ __pcp_packages + __pcp_packages_extra + pcp_optional_packages }}"

roles/pcp/tasks/pmcd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@
116116
- name: Ensure performance metric collector is running and enabled on boot
117117
service:
118118
name: pmcd
119-
state: started
119+
state: "{{ 'started' if __pcp_is_booted else omit }}"
120120
enabled: true
121121
when: not __pcp_restart_pmcd | bool
122122

123123
- name: Ensure performance metric collector is restarted and enabled on boot
124124
service:
125125
name: pmcd
126-
state: restarted
126+
state: "{{ 'restarted' if __pcp_is_booted else omit }}"
127127
enabled: true
128128
when: __pcp_restart_pmcd | bool

roles/pcp/tasks/pmie.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@
127127
- name: Ensure performance metric inference is running and enabled on boot
128128
service:
129129
name: pmie
130-
state: started
130+
state: "{{ 'started' if __pcp_is_booted else omit }}"
131131
enabled: true
132132
when: not __pcp_restart_pmie | bool
133133

134134
- name: Ensure performance metric inference is restarted and enabled on boot
135135
service:
136136
name: pmie
137-
state: restarted
137+
state: "{{ 'restarted' if __pcp_is_booted else omit }}"
138138
enabled: true
139139
when: __pcp_restart_pmie | bool

roles/pcp/tasks/pmlogger.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
- name: Ensure performance metric logging is running and enabled on boot
5959
service:
6060
name: pmlogger
61-
state: started
61+
state: "{{ 'started' if __pcp_is_booted else omit }}"
6262
enabled: true
6363
when: not __pcp_restart_pmlogger | bool
6464

6565
- name: Ensure performance metric logging is restarted and enabled on boot
6666
service:
6767
name: pmlogger
68-
state: restarted
68+
state: "{{ 'restarted' if __pcp_is_booted else omit }}"
6969
enabled: true
7070
when: __pcp_restart_pmlogger | bool

0 commit comments

Comments
 (0)