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

[pkgng] present the 'ignore_osver' option to pkg (#1243)

* [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 <egypcio@googlemail.com>

* [pkgng] create changelog fragment for PR #1243

Signed-off-by: Vinicius Zavam <egypcio@googlemail.com>

* [pkgng] add information about when we start to offer 'ignoreosver'

Signed-off-by: Vinicius Zavam <egypcio@googlemail.com>

* [pkgng] rename 'ignoreosver' -> 'ignore_osver'

Signed-off-by: Vinicius Zavam <egypcio@googlemail.com>

* [pkgng] remove unnecessary backslashes for install_packages() call

Signed-off-by: Vinicius Zavam <egypcio@googlemail.com>

* [pkgng] fix changelog fragment's formating

Signed-off-by: Vinicius Zavam <egypcio@googlemail.com>
This commit is contained in:
Vinícius Zavam 2020-11-17 06:17:16 +00:00 committed by GitHub
parent 9787e8a6bf
commit d95910963b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- pkgng - present the ``ignore_osver`` option to pkg (https://github.com/ansible-collections/community.general/pull/1243).

View file

@ -90,6 +90,14 @@ options:
required: false required: false
type: bool type: bool
default: no 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)" author: "bleader (@bleader)"
notes: notes:
- When using pkgsite, be careful that already in cache packages won't be downloaded again. - 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) 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 install_c = 0
stdout = "" stdout = ""
stderr = "" stderr = ""
@ -235,11 +243,16 @@ def install_packages(module, pkgng_path, packages, cached, pkgsite, dir_arg, sta
# setting them to their default values. # setting them to their default values.
batch_var = 'env BATCH=yes' 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 not module.check_mode and not cached:
if old_pkgng: if old_pkgng:
rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgng_path)) rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgng_path))
else: 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 stdout += out
stderr += err stderr += err
if rc != 0: if rc != 0:
@ -387,6 +400,7 @@ def main():
state=dict(default="present", choices=["present", "latest", "absent"], required=False), state=dict(default="present", choices=["present", "latest", "absent"], required=False),
name=dict(aliases=["pkg"], required=True, type='list', elements='str'), name=dict(aliases=["pkg"], required=True, type='list', elements='str'),
cached=dict(default=False, type='bool'), cached=dict(default=False, type='bool'),
ignore_osver=dict(default=False, required=False, type='bool'),
annotation=dict(default="", required=False), annotation=dict(default="", required=False),
pkgsite=dict(default="", required=False), pkgsite=dict(default="", required=False),
rootdir=dict(default="", required=False, type='path'), rootdir=dict(default="", required=False, type='path'),
@ -415,6 +429,11 @@ def main():
else: else:
dir_arg = "--rootdir %s" % (p["rootdir"]) 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"] != "": if p["chroot"] != "":
dir_arg = '--chroot %s' % (p["chroot"]) dir_arg = '--chroot %s' % (p["chroot"])
@ -432,7 +451,9 @@ def main():
# Operate on named packages # Operate on named packages
named_packages = [pkg for pkg in pkgs if pkg != '*'] named_packages = [pkg for pkg in pkgs if pkg != '*']
if p["state"] in ("present", "latest") and named_packages: 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 stdout += _out
stderr += _err stderr += _err
changed = changed or _changed changed = changed or _changed