1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

feature(yum_versionlock): add support to pin specific package versions (#6861)

feature(yum_versionlock): add support to pin specific package versions instead of only the package itself
This commit is contained in:
Florian 2023-07-12 22:23:44 +02:00 committed by GitHub
parent 9adc82d5d1
commit 2bf85cca51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- yum_versionlock - add support to pin specific package versions instead of only the package itself (https://github.com/ansible-collections/community.general/pull/6861, https://github.com/ansible-collections/community.general/issues/4470).

View file

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2018, Florian Paul Azim Hoberg <florian.hoberg@credativ.de> # Copyright (c) 2018, Florian Paul Azim Hoberg (@gyptazy) <gyptazy@gyptazy.ch>
# #
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
@ -25,7 +25,8 @@ attributes:
options: options:
name: name:
description: description:
- Package name or a list of package names with optional wildcards. - Package name or a list of package names with optional version or wildcards.
- Specifying versions is supported since community.general 7.2.0.
type: list type: list
required: true required: true
elements: str elements: str
@ -50,7 +51,14 @@ EXAMPLES = r'''
- name: Prevent Apache / httpd from being updated - name: Prevent Apache / httpd from being updated
community.general.yum_versionlock: community.general.yum_versionlock:
state: present state: present
name: httpd name:
- httpd
- name: Prevent Apache / httpd version 2.4.57-2 from being updated
community.general.yum_versionlock:
state: present
name:
- httpd-0:2.4.57-2.el9
- name: Prevent multiple packages from being updated - name: Prevent multiple packages from being updated
community.general.yum_versionlock: community.general.yum_versionlock:
@ -111,22 +119,30 @@ class YumVersionLock:
def ensure_state(self, packages, command): def ensure_state(self, packages, command):
""" Ensure packages state """ """ Ensure packages state """
rc, out, err = self.module.run_command([self.yum_bin, "-q", "versionlock", command] + packages) rc, out, err = self.module.run_command([self.yum_bin, "-q", "versionlock", command] + packages)
# If no package can be found this will be written on stdout with rc 0
if 'No package found for' in out:
self.module.fail_json(msg=out)
if rc == 0: if rc == 0:
return True return True
self.module.fail_json(msg="Error: " + to_native(err) + to_native(out)) self.module.fail_json(msg="Error: " + to_native(err) + to_native(out))
def match(entry, name): def match(entry, name):
match = False
m = NEVRA_RE_YUM.match(entry) m = NEVRA_RE_YUM.match(entry)
if not m: if not m:
m = NEVRA_RE_DNF.match(entry) m = NEVRA_RE_DNF.match(entry)
if not m: if not m:
return False return False
return fnmatch(m.group("name"), name) if fnmatch(m.group("name"), name):
match = True
if entry.rstrip('.*') == name:
match = True
return match
def main(): def main():
""" start main program to add/remove a package to yum versionlock""" """ start main program to add/delete a package to yum versionlock """
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
state=dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),