Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tasks/set_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
difference(ansible_facts.keys() | list) | length > 0

- name: Determine if system is booted with systemd
when: not __cockpit_is_booted is defined
when: __cockpit_is_booted is not defined
block:
- name: Run systemctl
# noqa command-instead-of-module
Expand All @@ -15,13 +15,18 @@
changed_when: false
failed_when: false

- name: Require installed systemd
fail:
msg: "Error: This role requires systemd to be installed."
when: '"No such file or directory" in __is_system_running.msg | d("")'
Comment on lines +18 to +21
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use explicit binary existence check or Ansible fact instead of parsing error message

Use the stat module to check for /usr/bin/systemctl or use the ansible_service_mgr fact instead of parsing error output. This avoids fragility from output changes or localization.

Suggested change
- name: Require installed systemd
fail:
msg: "Error: This role requires systemd to be installed."
when: '"No such file or directory" in __is_system_running.msg | d("")'
- name: Check for systemctl binary
stat:
path: /usr/bin/systemctl
register: systemctl_stat
- name: Require installed systemd
fail:
msg: "Error: This role requires systemd to be installed."
when: not systemctl_stat.stat.exists


- name: Set flag to indicate that systemd runtime operations are available
set_fact:
# see https://www.man7.org/linux/man-pages/man1/systemctl.1.html#:~:text=is-system-running%20output
__cockpit_is_booted: "{{ __is_system_running.stdout not in ['offline', 'degraded'] }}"
__cockpit_is_booted: "{{ __is_system_running.stdout != 'offline' }}"

- name: Determine if system is ostree and set flag
when: not __cockpit_is_ostree is defined
when: __cockpit_is_ostree is not defined
block:
- name: Check if system is ostree
stat:
Expand Down
Loading