diff --git a/changelogs/fragments/1912-yum_versionlock-lock_unlock_concurrently.yml b/changelogs/fragments/1912-yum_versionlock-lock_unlock_concurrently.yml new file mode 100644 index 0000000000..36f40da0fe --- /dev/null +++ b/changelogs/fragments/1912-yum_versionlock-lock_unlock_concurrently.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - yum_versionlock - Do the lock/unlock concurrently to speed up (https://github.com/ansible-collections/community.general/pull/1912). diff --git a/plugins/modules/packaging/os/yum_versionlock.py b/plugins/modules/packaging/os/yum_versionlock.py index 0830b3a4ab..13319f6711 100644 --- a/plugins/modules/packaging/os/yum_versionlock.py +++ b/plugins/modules/packaging/os/yum_versionlock.py @@ -13,7 +13,7 @@ module: yum_versionlock version_added: 2.0.0 short_description: Locks / unlocks a installed package(s) from being updated by yum package manager description: - - This module adds installed packages to yum versionlock to prevent the package from being updated. + - This module adds installed packages to yum versionlock to prevent the package(s) from being updated. options: name: description: @@ -93,9 +93,9 @@ class YumVersionLock: self.module.fail_json(msg="Error: Please install rpm package yum-plugin-versionlock : " + to_native(err) + to_native(out)) self.module.fail_json(msg="Error: " + to_native(err) + to_native(out)) - def ensure_state(self, package, command): - """ Ensure package state """ - rc, out, err = self.module.run_command([self.yum_bin, "-q", "versionlock", command, package]) + def ensure_state(self, packages, command): + """ Ensure packages state """ + rc, out, err = self.module.run_command([self.yum_bin, "-q", "versionlock", command] + packages) if rc == 0: return True self.module.fail_json(msg="Error: " + to_native(err) + to_native(out)) @@ -121,6 +121,7 @@ def main(): versionlock_packages = yum_v.get_versionlock_packages() # Ensure versionlock state of packages + packages_list = [] if state in ('present'): command = 'add' for single_pkg in packages: @@ -128,7 +129,9 @@ def main(): if module.check_mode: changed = True continue - changed = yum_v.ensure_state(single_pkg, command) + packages_list.append(single_pkg) + if packages_list: + changed = yum_v.ensure_state(packages_list, command) elif state in ('absent'): command = 'delete' for single_pkg in packages: @@ -136,7 +139,9 @@ def main(): if module.check_mode: changed = True continue - changed = yum_v.ensure_state(single_pkg, command) + packages_list.append(single_pkg) + if packages_list: + changed = yum_v.ensure_state(packages_list, command) module.exit_json( changed=changed, diff --git a/tests/integration/targets/yum_versionlock/aliases b/tests/integration/targets/yum_versionlock/aliases index 895088b2c6..abe0a21e22 100644 --- a/tests/integration/targets/yum_versionlock/aliases +++ b/tests/integration/targets/yum_versionlock/aliases @@ -1,4 +1,3 @@ -disabled # The tests are way too slow - the locking/unlocking steps need 10 minutes each! shippable/posix/group1 skip/aix skip/freebsd