Add the options apply_live to rpm_ostree_pkg (#9167)
rpm_ostree_pkg: add support for `apply_live` and return value `needs_reboot` #9167pull/8360/merge
parent
f828bdee22
commit
420f78de2f
|
@ -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).
|
|
@ -40,6 +40,14 @@ options:
|
||||||
choices: [ 'absent', 'present' ]
|
choices: [ 'absent', 'present' ]
|
||||||
default: 'present'
|
default: 'present'
|
||||||
type: str
|
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:
|
author:
|
||||||
- Dusty Mabe (@dustymabe)
|
- Dusty Mabe (@dustymabe)
|
||||||
- Abhijeet Kasurde (@Akasurde)
|
- Abhijeet Kasurde (@Akasurde)
|
||||||
|
@ -56,6 +64,12 @@ EXAMPLES = r'''
|
||||||
name: nfs-utils
|
name: nfs-utils
|
||||||
state: absent
|
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.
|
# In case a different transaction is currently running the module would fail.
|
||||||
# Adding a delay can help mitigate this problem:
|
# Adding a delay can help mitigate this problem:
|
||||||
- name: Install overlay package
|
- name: Install overlay package
|
||||||
|
@ -104,6 +118,12 @@ cmd:
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
sample: 'rpm-ostree uninstall --allow-inactive --idempotent --unchanged-exit-77 nfs-utils'
|
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
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
@ -124,19 +144,24 @@ class RpmOstreePkg:
|
||||||
stdout='',
|
stdout='',
|
||||||
stderr='',
|
stderr='',
|
||||||
cmd='',
|
cmd='',
|
||||||
|
needs_reboot=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Ensure rpm-ostree command exists
|
# Ensure rpm-ostree command exists
|
||||||
cmd = [self.module.get_bin_path('rpm-ostree', required=True)]
|
cmd = [self.module.get_bin_path('rpm-ostree', required=True)]
|
||||||
|
|
||||||
# Decide action to perform
|
# Decide action to perform
|
||||||
if self.state in ('present'):
|
if self.state == 'present':
|
||||||
results['action'] = 'install'
|
results['action'] = 'install'
|
||||||
cmd.append('install')
|
cmd.append('install')
|
||||||
elif self.state in ('absent'):
|
elif self.state == 'absent':
|
||||||
results['action'] = 'uninstall'
|
results['action'] = 'uninstall'
|
||||||
cmd.append('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
|
# Additional parameters
|
||||||
cmd.extend(['--allow-inactive', '--idempotent', '--unchanged-exit-77'])
|
cmd.extend(['--allow-inactive', '--idempotent', '--unchanged-exit-77'])
|
||||||
for pkg in self.params['name']:
|
for pkg in self.params['name']:
|
||||||
|
@ -145,6 +170,10 @@ class RpmOstreePkg:
|
||||||
|
|
||||||
rc, out, err = self.module.run_command(cmd)
|
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(
|
results.update(dict(
|
||||||
rc=rc,
|
rc=rc,
|
||||||
cmd=' '.join(cmd),
|
cmd=' '.join(cmd),
|
||||||
|
@ -180,6 +209,10 @@ def main():
|
||||||
type='list',
|
type='list',
|
||||||
elements='str',
|
elements='str',
|
||||||
),
|
),
|
||||||
|
apply_live=dict(
|
||||||
|
type='bool',
|
||||||
|
default=False,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue