From 420f78de2fea14de761b4e326fa500544139e3a9 Mon Sep 17 00:00:00 2001 From: shios86 <17804953+shios86@users.noreply.github.com> Date: Thu, 28 Nov 2024 06:51:21 +0100 Subject: [PATCH] Add the options apply_live to rpm_ostree_pkg (#9167) rpm_ostree_pkg: add support for `apply_live` and return value `needs_reboot` #9167 --- .../9167-rpm_ostree_pkg-apply_live.yml | 3 ++ plugins/modules/rpm_ostree_pkg.py | 37 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/9167-rpm_ostree_pkg-apply_live.yml diff --git a/changelogs/fragments/9167-rpm_ostree_pkg-apply_live.yml b/changelogs/fragments/9167-rpm_ostree_pkg-apply_live.yml new file mode 100644 index 0000000000..e473dedd0b --- /dev/null +++ b/changelogs/fragments/9167-rpm_ostree_pkg-apply_live.yml @@ -0,0 +1,3 @@ +minor_changes: +- rpm_ostree_pkg - added the options ``apply_live`` (https://github.com/ansible-collections/community.general/pull/9167). +- rpm_ostree_pkg - added the return value ``needs_reboot`` (https://github.com/ansible-collections/community.general/pull/9167). diff --git a/plugins/modules/rpm_ostree_pkg.py b/plugins/modules/rpm_ostree_pkg.py index 1a02b2d71c..8c5c693f60 100644 --- a/plugins/modules/rpm_ostree_pkg.py +++ b/plugins/modules/rpm_ostree_pkg.py @@ -40,6 +40,14 @@ options: choices: [ 'absent', 'present' ] default: 'present' type: str + apply_live: + description: + - Adds the options C(--apply-live) when O(state=present). + - Option is ignored when O(state=absent). + - For more information, please see U(https://coreos.github.io/rpm-ostree/apply-live/). + type: bool + default: false + version_added: 10.1.0 author: - Dusty Mabe (@dustymabe) - Abhijeet Kasurde (@Akasurde) @@ -56,6 +64,12 @@ EXAMPLES = r''' name: nfs-utils state: absent +- name: Apply the overlay package live + community.general.rpm_ostree: + name: nfs-utils + state: present + apply_live: true + # In case a different transaction is currently running the module would fail. # Adding a delay can help mitigate this problem: - name: Install overlay package @@ -104,6 +118,12 @@ cmd: returned: always type: str sample: 'rpm-ostree uninstall --allow-inactive --idempotent --unchanged-exit-77 nfs-utils' +needs_reboot: + description: Determine if machine needs a reboot to apply current changes. + returned: success + type: bool + sample: true + version_added: 10.1.0 ''' from ansible.module_utils.basic import AnsibleModule @@ -124,19 +144,24 @@ class RpmOstreePkg: stdout='', stderr='', cmd='', + needs_reboot=False, ) # Ensure rpm-ostree command exists cmd = [self.module.get_bin_path('rpm-ostree', required=True)] # Decide action to perform - if self.state in ('present'): + if self.state == 'present': results['action'] = 'install' cmd.append('install') - elif self.state in ('absent'): + elif self.state == 'absent': results['action'] = 'uninstall' cmd.append('uninstall') + # Add the options to the command line + if self.params['apply_live'] and self.state == 'present': + cmd.extend(['--apply-live', '--assumeyes']) + # Additional parameters cmd.extend(['--allow-inactive', '--idempotent', '--unchanged-exit-77']) for pkg in self.params['name']: @@ -145,6 +170,10 @@ class RpmOstreePkg: rc, out, err = self.module.run_command(cmd) + # Determine if system needs a reboot to apply change + if 'Changes queued for next boot. Run "systemctl reboot" to start a reboot' in out: + results['needs_reboot'] = True + results.update(dict( rc=rc, cmd=' '.join(cmd), @@ -180,6 +209,10 @@ def main(): type='list', elements='str', ), + apply_live=dict( + type='bool', + default=False, + ), ), )