yum_versionlock: fix idempotency when using wildcard (asterisk) (#2787)

* Check idempotency on yum_versionlock

* Lock packages wildcard

* fix formatting

Co-authored-by: Felix Fontein <felix@fontein.de>

* Fix formatting in asserts

* little closer but not still there

* Import fnmatch

* Change check_mode logic

* Add check_mode for add

* Add changelog

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Amin Vakil 2021-06-27 19:10:49 +04:30 committed by GitHub
commit 0a9cf38118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 14 deletions

View file

@ -76,6 +76,7 @@ state:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from fnmatch import fnmatch
class YumVersionLock:
@ -125,23 +126,23 @@ def main():
if state in ('present'):
command = 'add'
for single_pkg in packages:
if single_pkg not in versionlock_packages:
if module.check_mode:
changed = True
continue
if not any(fnmatch(pkg.split(":", 1)[-1], single_pkg) for pkg in versionlock_packages.split()):
packages_list.append(single_pkg)
if packages_list:
changed = yum_v.ensure_state(packages_list, command)
if module.check_mode:
changed = True
else:
changed = yum_v.ensure_state(packages_list, command)
elif state in ('absent'):
command = 'delete'
for single_pkg in packages:
if single_pkg in versionlock_packages:
if module.check_mode:
changed = True
continue
if any(fnmatch(pkg, single_pkg) for pkg in versionlock_packages.split()):
packages_list.append(single_pkg)
if packages_list:
changed = yum_v.ensure_state(packages_list, command)
if module.check_mode:
changed = True
else:
changed = yum_v.ensure_state(packages_list, command)
module.exit_json(
changed=changed,