Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dpkg_selections fixes for 'unprimed' pkgs #83088

Draft
wants to merge 3 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/dpkg_selections_fix.yml
@@ -0,0 +1,2 @@
bugfixes:
- dpkg_selections now handles existing, but not primed, packages correctly.
17 changes: 11 additions & 6 deletions lib/ansible/modules/dpkg_selections.py
Expand Up @@ -76,19 +76,24 @@ def main():

# Get current settings.
rc, out, err = module.run_command([dpkg, '--get-selections', name], check_rc=True)
if 'no packages found matching' in err:
module.fail_json(msg="Failed to find package '%s' to perform selection '%s'." % (name, selection))
elif not out:
current = 'not present'
else:
if rc == 0 and out:
current = out.split()[1]
elif 'no packages found matching' in err:
current = 'not found'
else:
current = 'not present'

changed = current != selection

if module.check_mode or not changed:
module.exit_json(changed=changed, before=current, after=selection)

module.run_command([dpkg, '--set-selections'], data="%s %s" % (name, selection), check_rc=True)
rc, out, err = module.run_command([dpkg, '--set-selections'], data="%s %s" % (name, selection), check_rc=True)
if rc != 0:
if 'package not in' in err:
module.fail_json(msg="Failed to find package '%s' to perform selection '%s'." % (name, selection))
module.fail_json(msg="Unexpected error when setting package '%s' to '%s': %s." % (name, selection, err))

module.exit_json(changed=changed, before=current, after=selection)


Expand Down
Expand Up @@ -90,7 +90,7 @@

- name: Try to select non-existent package
dpkg_selections:
name: kernel
name: kerfufle_bad_name_test
selection: hold
ignore_errors: yes
register: result
Expand Down