[dnf] show installations/removals in check_mode (#70892)
Change: - Previously, we only showed that something would have changed, not what would have changed. This allows us to show what will chang as well. Test Plan: - Local RHEL8 VM - New integration tests Tickets: - Fixes #66132 Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
parent
ae42d5ebdc
commit
7d32129efb
3 changed files with 76 additions and 6 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- dnf - now shows specific package changes (installations/removals) under ``results`` in check_mode. (https://github.com/ansible/ansible/issues/66132)
|
|
@ -1158,6 +1158,18 @@ class DnfModule(YumDnf):
|
||||||
self.module.exit_json(**response)
|
self.module.exit_json(**response)
|
||||||
else:
|
else:
|
||||||
response['changed'] = True
|
response['changed'] = True
|
||||||
|
|
||||||
|
# If packages got installed/removed, add them to the results.
|
||||||
|
# We do this early so we can use it for both check_mode and not.
|
||||||
|
if self.download_only:
|
||||||
|
install_action = 'Downloaded'
|
||||||
|
else:
|
||||||
|
install_action = 'Installed'
|
||||||
|
for package in self.base.transaction.install_set:
|
||||||
|
response['results'].append("{0}: {1}".format(install_action, package))
|
||||||
|
for package in self.base.transaction.remove_set:
|
||||||
|
response['results'].append("Removed: {0}".format(package))
|
||||||
|
|
||||||
if failure_response['failures']:
|
if failure_response['failures']:
|
||||||
failure_response['msg'] = 'Failed to install some of the specified packages'
|
failure_response['msg'] = 'Failed to install some of the specified packages'
|
||||||
self.module.fail_json(**failure_response)
|
self.module.fail_json(**failure_response)
|
||||||
|
@ -1178,15 +1190,11 @@ class DnfModule(YumDnf):
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.download_only:
|
if self.download_only:
|
||||||
for package in self.base.transaction.install_set:
|
# No further work left to do, and the results were already updated above.
|
||||||
response['results'].append("Downloaded: {0}".format(package))
|
# Just return them.
|
||||||
self.module.exit_json(**response)
|
self.module.exit_json(**response)
|
||||||
else:
|
else:
|
||||||
self.base.do_transaction()
|
self.base.do_transaction()
|
||||||
for package in self.base.transaction.install_set:
|
|
||||||
response['results'].append("Installed: {0}".format(package))
|
|
||||||
for package in self.base.transaction.remove_set:
|
|
||||||
response['results'].append("Removed: {0}".format(package))
|
|
||||||
|
|
||||||
if failure_response['failures']:
|
if failure_response['failures']:
|
||||||
failure_response['msg'] = 'Failed to install some of the specified packages'
|
failure_response['msg'] = 'Failed to install some of the specified packages'
|
||||||
|
|
|
@ -48,6 +48,20 @@
|
||||||
- "not dnf_result.changed"
|
- "not dnf_result.changed"
|
||||||
|
|
||||||
# INSTALL
|
# INSTALL
|
||||||
|
- name: install sos (check_mode)
|
||||||
|
dnf:
|
||||||
|
name: sos
|
||||||
|
state: present
|
||||||
|
update_cache: True
|
||||||
|
check_mode: True
|
||||||
|
register: dnf_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- dnf_result is success
|
||||||
|
- dnf_result.results|length > 0
|
||||||
|
- "dnf_result.results[0].startswith('Installed: ')"
|
||||||
|
|
||||||
- name: install sos
|
- name: install sos
|
||||||
dnf:
|
dnf:
|
||||||
name: sos
|
name: sos
|
||||||
|
@ -74,6 +88,18 @@
|
||||||
- "'results' in dnf_result"
|
- "'results' in dnf_result"
|
||||||
|
|
||||||
# INSTALL AGAIN
|
# INSTALL AGAIN
|
||||||
|
- name: install sos again (check_mode)
|
||||||
|
dnf:
|
||||||
|
name: sos
|
||||||
|
state: present
|
||||||
|
check_mode: True
|
||||||
|
register: dnf_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- dnf_result is not changed
|
||||||
|
- dnf_result.results|length == 0
|
||||||
|
|
||||||
- name: install sos again
|
- name: install sos again
|
||||||
dnf:
|
dnf:
|
||||||
name: sos
|
name: sos
|
||||||
|
@ -188,12 +214,33 @@
|
||||||
- "rpm_sos_result.rc == 0"
|
- "rpm_sos_result.rc == 0"
|
||||||
- "rpm_pciutils_result.rc == 0"
|
- "rpm_pciutils_result.rc == 0"
|
||||||
|
|
||||||
|
- name: uninstall sos and pciutils (check_mode)
|
||||||
|
dnf:
|
||||||
|
name:
|
||||||
|
- sos
|
||||||
|
- pciutils
|
||||||
|
state: removed
|
||||||
|
check_mode: True
|
||||||
|
register: dnf_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- dnf_result is success
|
||||||
|
- dnf_result.results|length == 2
|
||||||
|
- "dnf_result.results[0].startswith('Removed: ')"
|
||||||
|
- "dnf_result.results[1].startswith('Removed: ')"
|
||||||
|
|
||||||
- name: uninstall sos and pciutils
|
- name: uninstall sos and pciutils
|
||||||
dnf:
|
dnf:
|
||||||
name:
|
name:
|
||||||
- sos
|
- sos
|
||||||
- pciutils
|
- pciutils
|
||||||
state: removed
|
state: removed
|
||||||
|
register: dnf_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- dnf_result is changed
|
||||||
|
|
||||||
- name: install non-existent rpm
|
- name: install non-existent rpm
|
||||||
dnf:
|
dnf:
|
||||||
|
@ -238,6 +285,19 @@
|
||||||
name: sos
|
name: sos
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Test download_only (check_mode)
|
||||||
|
dnf:
|
||||||
|
name: sos
|
||||||
|
state: latest
|
||||||
|
download_only: true
|
||||||
|
check_mode: true
|
||||||
|
register: dnf_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- dnf_result is success
|
||||||
|
- "dnf_result.results[0].startswith('Downloaded: ')"
|
||||||
|
|
||||||
- name: Test download_only
|
- name: Test download_only
|
||||||
dnf:
|
dnf:
|
||||||
name: sos
|
name: sos
|
||||||
|
|
Loading…
Reference in a new issue