mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add partial diff support, not in check mode to openbsd_pkg (#8402)
* Add partial diff support, not in check mode * Add changelog fragment * Fix PEP8. Want to run Black against this so badly. * Update changelogs/fragments/8402-add-diif-mode-openbsd-pkg.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/openbsd_pkg.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/openbsd_pkg.py Co-authored-by: Felix Fontein <felix@fontein.de> * Remove unneeded comment --------- Co-authored-by: Allen Smith <allsmith@allsmith.users.ipa.redhat.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
572caeaa39
commit
e690317e3a
2 changed files with 27 additions and 1 deletions
2
changelogs/fragments/8402-add-diif-mode-openbsd-pkg.yml
Normal file
2
changelogs/fragments/8402-add-diif-mode-openbsd-pkg.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- openbsd_pkg - adds diff support to show changes in installed package list. This does not yet work for check mode (https://github.com/ansible-collections/community.general/pull/8402).
|
|
@ -24,7 +24,10 @@ attributes:
|
|||
check_mode:
|
||||
support: full
|
||||
diff_mode:
|
||||
support: none
|
||||
support: partial
|
||||
version_added: 9.1.0
|
||||
details:
|
||||
- Only works when check mode is not enabled.
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
|
@ -159,6 +162,20 @@ def execute_command(cmd, module):
|
|||
return module.run_command(cmd_args, environ_update={'TERM': 'dumb'})
|
||||
|
||||
|
||||
def get_all_installed(module):
|
||||
"""
|
||||
Get all installed packaged. Used to support diff mode
|
||||
"""
|
||||
command = 'pkg_info -Iq'
|
||||
|
||||
rc, stdout, stderr = execute_command(command, module)
|
||||
|
||||
if stderr:
|
||||
module.fail_json(msg="failed in get_all_installed(): %s" % stderr)
|
||||
|
||||
return stdout
|
||||
|
||||
|
||||
# Function used to find out if a package is currently installed.
|
||||
def get_package_state(names, pkg_spec, module):
|
||||
info_cmd = 'pkg_info -Iq'
|
||||
|
@ -573,10 +590,13 @@ def main():
|
|||
result['name'] = name
|
||||
result['state'] = state
|
||||
result['build'] = build
|
||||
result['diff'] = {}
|
||||
|
||||
# The data structure used to keep track of package information.
|
||||
pkg_spec = {}
|
||||
|
||||
new_package_list = original_package_list = get_all_installed(module)
|
||||
|
||||
if build is True:
|
||||
if not os.path.isdir(ports_dir):
|
||||
module.fail_json(msg="the ports source directory %s does not exist" % (ports_dir))
|
||||
|
@ -661,6 +681,10 @@ def main():
|
|||
|
||||
result['changed'] = combined_changed
|
||||
|
||||
if result['changed'] and not module.check_mode:
|
||||
new_package_list = get_all_installed(module)
|
||||
result['diff'] = dict(before=original_package_list, after=new_package_list)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue