Skip to content

Commit

Permalink
[PR #9167/420f78de backport][stable-10] Add the options apply_live to…
Browse files Browse the repository at this point in the history
… rpm_ostree_pkg (#9208)

Add the options apply_live to rpm_ostree_pkg (#9167)

rpm_ostree_pkg: add support for `apply_live` and return value `needs_reboot` #9167

(cherry picked from commit 420f78d)

Co-authored-by: shios86 <[email protected]>
  • Loading branch information
patchback[bot] and shios86 authored Nov 28, 2024
1 parent 5491ff7 commit 09f99e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/9167-rpm_ostree_pkg-apply_live.yml
Original file line number Diff line number Diff line change
@@ -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).
37 changes: 35 additions & 2 deletions plugins/modules/rpm_ostree_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
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)
Expand All @@ -56,6 +64,12 @@
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
Expand Down Expand Up @@ -104,6 +118,12 @@
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
Expand All @@ -124,19 +144,24 @@ def ensure(self):
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']:
Expand All @@ -145,6 +170,10 @@ def ensure(self):

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),
Expand Down Expand Up @@ -180,6 +209,10 @@ def main():
type='list',
elements='str',
),
apply_live=dict(
type='bool',
default=False,
),
),
)

Expand Down

0 comments on commit 09f99e6

Please sign in to comment.