From c1a6feaf2562cae4a9edb29abcaad6719bfabb2e Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2020 07:37:00 +0100 Subject: [PATCH] [pkgng] present the 'ignore_osver' option to pkg (#1243) (#1321) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pkgng] introduce IGNORE_OSVERSION to pkgng * [pkgng] add small description about IGNORE_OSVERSION - source: https://www.freebsd.org/cgi/man.cgi?query=pkg.conf&sektion=5 * [pkgng] initialize default value of 'ignoreosver' as False * [pkgng] replace double quotes by single ones, when setting 'ignoreosver' * [pkgng] do not make 'ignoreosver' a required option for this module * [pkgng] mode the point we set IGNORE_OSVER into install_packages() * [pkgng] restrict the use of 'ignoreosver' to pkg versions >= 1.11 - https://github.com/freebsd/pkg/blob/release-1.11/NEWS#L51 * [pkgng] value of 'ignoreosver' passed to install_packages - install_packages() contains a taks to update local pkgs cache; - should that update be triggered, AND 'ignoreosver' is set to True, we must change existing "batch_var" and add the IGNORE_OSVERSION=yes to the environment; - there pkg running on STABLE or CURRENT FreeBSD machines will have a chance to proceed with the "update" action * [pkgng] create option description for "ignoreosver" and its defaults * [pkgng] make sure we do use IGNORE_OSVERSION when action is "update" * [pkgng] add more information on how 'ignoreosver' works Signed-off-by: Vinicius Zavam * [pkgng] create changelog fragment for PR #1243 Signed-off-by: Vinicius Zavam * [pkgng] add information about when we start to offer 'ignoreosver' Signed-off-by: Vinicius Zavam * [pkgng] rename 'ignoreosver' -> 'ignore_osver' Signed-off-by: Vinicius Zavam * [pkgng] remove unnecessary backslashes for install_packages() call Signed-off-by: Vinicius Zavam * [pkgng] fix changelog fragment's formating Signed-off-by: Vinicius Zavam (cherry picked from commit d95910963b87e9efba2aed1b527a2f8e4d6ee7ae) Co-authored-by: Vinícius Zavam --- .../1243-pkgng-present-ignoreosver.yaml | 2 ++ plugins/modules/packaging/os/pkgng.py | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/1243-pkgng-present-ignoreosver.yaml diff --git a/changelogs/fragments/1243-pkgng-present-ignoreosver.yaml b/changelogs/fragments/1243-pkgng-present-ignoreosver.yaml new file mode 100644 index 0000000000..5f06075f8b --- /dev/null +++ b/changelogs/fragments/1243-pkgng-present-ignoreosver.yaml @@ -0,0 +1,2 @@ +minor_changes: + - pkgng - present the ``ignore_osver`` option to pkg (https://github.com/ansible-collections/community.general/pull/1243). diff --git a/plugins/modules/packaging/os/pkgng.py b/plugins/modules/packaging/os/pkgng.py index c4f6b497f4..d5ed4a0c5a 100644 --- a/plugins/modules/packaging/os/pkgng.py +++ b/plugins/modules/packaging/os/pkgng.py @@ -90,6 +90,14 @@ options: required: false type: bool default: no + ignore_osver: + description: + - Ignore FreeBSD OS version check, useful on -STABLE and -CURRENT branches. + - Defines the C(IGNORE_OSVERSION) environment variable. + required: false + type: bool + default: no + version_added: 1.3.0 author: "bleader (@bleader)" notes: - When using pkgsite, be careful that already in cache packages won't be downloaded again. @@ -217,7 +225,7 @@ def remove_packages(module, pkgng_path, packages, dir_arg): return (False, "package(s) already absent", stdout, stderr) -def install_packages(module, pkgng_path, packages, cached, pkgsite, dir_arg, state): +def install_packages(module, pkgng_path, packages, cached, pkgsite, dir_arg, state, ignoreosver): install_c = 0 stdout = "" stderr = "" @@ -235,11 +243,16 @@ def install_packages(module, pkgng_path, packages, cached, pkgsite, dir_arg, sta # setting them to their default values. batch_var = 'env BATCH=yes' + if ignoreosver: + # Ignore FreeBSD OS version check, + # useful on -STABLE and -CURRENT branches. + batch_var = batch_var + ' IGNORE_OSVERSION=yes' + if not module.check_mode and not cached: if old_pkgng: rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgng_path)) else: - rc, out, err = module.run_command("%s %s update" % (pkgng_path, dir_arg)) + rc, out, err = module.run_command("%s %s %s update" % (batch_var, pkgng_path, dir_arg)) stdout += out stderr += err if rc != 0: @@ -387,6 +400,7 @@ def main(): state=dict(default="present", choices=["present", "latest", "absent"], required=False), name=dict(aliases=["pkg"], required=True, type='list', elements='str'), cached=dict(default=False, type='bool'), + ignore_osver=dict(default=False, required=False, type='bool'), annotation=dict(default="", required=False), pkgsite=dict(default="", required=False), rootdir=dict(default="", required=False, type='path'), @@ -415,6 +429,11 @@ def main(): else: dir_arg = "--rootdir %s" % (p["rootdir"]) + if p["ignore_osver"]: + old_pkgng = pkgng_older_than(module, pkgng_path, [1, 11, 0]) + if old_pkgng: + module.fail_json(msg="To use option 'ignore_osver' pkg version must be 1.11 or greater") + if p["chroot"] != "": dir_arg = '--chroot %s' % (p["chroot"]) @@ -432,7 +451,9 @@ def main(): # Operate on named packages named_packages = [pkg for pkg in pkgs if pkg != '*'] if p["state"] in ("present", "latest") and named_packages: - _changed, _msg, _out, _err = install_packages(module, pkgng_path, named_packages, p["cached"], p["pkgsite"], dir_arg, p["state"]) + _changed, _msg, _out, _err = install_packages(module, pkgng_path, named_packages, + p["cached"], p["pkgsite"], dir_arg, + p["state"], p["ignore_osver"]) stdout += _out stderr += _err changed = changed or _changed