Add the options apply_live to rpm_ostree_pkg (#9167)

rpm_ostree_pkg: add support for `apply_live` and return value `needs_reboot` #9167
pull/8360/merge
shios86 2024-11-28 06:51:21 +01:00 committed by GitHub
parent f828bdee22
commit 420f78de2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 2 deletions

View File

@ -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).

View File

@ -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,
),
),
)