Skip to content

Commit

Permalink
ci: add support for transactional update
Browse files Browse the repository at this point in the history
  • Loading branch information
HVSharma12 authored and richm committed Jul 16, 2024
1 parent e623ea6 commit 4c77c1d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ supported policydb module version on target systems, i.e. on the oldest system.
**Note:** Managing modules is idempotent only on Fedora, and EL 8.6 and later.
You can manage modules on older releases, but it will not be idempotent.

### selinux_transactional_update_reboot_ok

This variable is used to handle reboots required by transactional updates. If a transactional update requires a reboot, the role will proceed with the reboot if selinux_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.

```yaml
selinux_transactional_update_reboot_ok: true
```

## Ansible Facts

### selinux_reboot_required
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
selinux_state: null
selinux_policy: null
selinux_transactional_update_reboot_ok: null

# Set up empty lists for SELinux changes.
selinux_booleans: []
Expand Down
38 changes: 38 additions & 0 deletions tasks/ensure_selinux_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
set_fact:
__selinux_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"

- name: Determine if system is transactional update and set flag
when: not __selinux_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:
__selinux_is_transactional: "{{ __transactional_update_stat.stat.exists }}"

- name: Install SELinux python2 tools
package:
name:
Expand Down Expand Up @@ -44,6 +56,7 @@
when:
- ansible_python_version is version('3', '>=')
- ansible_os_family == "Suse"
register: selinux_python3_tools_result

- name: Install SELinux tool semanage
package:
Expand All @@ -53,8 +66,33 @@
use: "{{ (__selinux_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when: ansible_distribution == "Fedora" or
ansible_distribution == "SL-Micro" or
(ansible_distribution_major_version | int > 7 and
ansible_distribution in ["CentOS", "RedHat", "Rocky"])
register: selinux_semanage_result

- name: Handle reboot for transactional update systems
when:
- __selinux_is_transactional | d(false)
- selinux_python3_tools_result is changed or
selinux_semanage_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: selinux_transactional_update_reboot_ok | bool

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

- name: Refresh facts
setup:
Expand Down
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ __selinux_required_facts_subsets: "{{ ['!all', '!min'] +
__selinux_required_facts }}"

restorecon_threads: "{{ '-T 0' if ansible_distribution == 'Fedora' or
ansible_distribution == 'SL-Micro' or
(ansible_distribution_major_version | int > 8 and
ansible_distribution in ['CentOS', 'RedHat', 'Rocky']) else '' }}"

0 comments on commit 4c77c1d

Please sign in to comment.