Skip to content

Commit

Permalink
ci: Handle reboot for transactional update systems
Browse files Browse the repository at this point in the history
  • Loading branch information
HVSharma12 authored and richm committed Aug 16, 2024
1 parent d91cf41 commit 55f0297
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@ Boolean - default is `false` - by default, the role will not prune unused images
when removing quadlets and other resources. Set this to `true` to tell the role
to remove unused images when cleaning up.

### podman_transactional_update_reboot_ok

This variable is applicable only for transactional update systems.
If a transactional update requires a reboot, the role will proceed with the
reboot if `podman_transactional_update_reboot_ok` is set to `true`. If set
to `false`, the role will notify the user that a reboot is required, allowing
for custom handling of the reboot requirement. If this variable is not set,
the role will fail to ensure the reboot requirement is not overlooked.
For non-transactional update systems, this variable is ignored.

## Variables Exported by the Role

### podman_version
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ podman_validate_certs: null
# Prune images when removing quadlets/kube specs -
# this will remove all unused/unreferenced images
podman_prune_images: false

# var to manage reboots for transactional update systems
podman_transactional_update_reboot_ok: null
24 changes: 24 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
become: true
when: (__podman_packages | difference(ansible_facts.packages))
register: podman_package_result

- name: Handle reboot for transactional update systems
when:
- __podman_is_transactional | d(false)
- podman_package_result is changed
block:
- name: Notify user that reboot is needed to apply changes
debug:
msg: >
Reboot required to apply changes due to transactional updates.
- name: Reboot transactional update systems
reboot:
msg: Rebooting the system to apply transactional update changes.
when: podman_transactional_update_reboot_ok | bool

- name: Fail if reboot is needed and not set
fail:
msg: >
Reboot is required but not allowed. Please set
'podman_transactional_update_reboot_ok' to proceed.
when:
- podman_transactional_update_reboot_ok is none

- name: Get podman version
check_mode: false
Expand Down
12 changes: 12 additions & 0 deletions tasks/set_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
set_fact:
__podman_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"

- name: Determine if system is transactional update and set flag
when: not __podman_is_transactional is defined
block:
- name: Check if transactional-update exists in /sbin
stat:
path: /sbin/transactional-update
register: __transactional_update_stat

- name: Set flag if transactional-update exists
set_fact:
__podman_is_transactional: "{{ __transactional_update_stat.stat.exists }}"

- name: Set platform/version specific variables
include_vars: "{{ __vars_file }}"
loop:
Expand Down

0 comments on commit 55f0297

Please sign in to comment.