mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Added support for pkgng multiple repositories.
Currently checking if pkgng >= 1.1.4, as specified in https://wiki.freebsd.org/pkgng . I guess that's when using PKGSITE was deprecated.
This commit is contained in:
parent
297b048d0e
commit
880eaf38a6
1 changed files with 36 additions and 6 deletions
|
@ -48,8 +48,11 @@ options:
|
||||||
default: no
|
default: no
|
||||||
pkgsite:
|
pkgsite:
|
||||||
description:
|
description:
|
||||||
- specify packagesite to use for downloading packages, if
|
- for pkgng versions before 1.1.4, specify packagesite to use
|
||||||
not specified, use settings from /usr/local/etc/pkg.conf
|
for downloading packages, if not specified, use settings from
|
||||||
|
/usr/local/etc/pkg.conf
|
||||||
|
for newer pkgng versions, specify a the name of a repository
|
||||||
|
configured in /usr/local/etc/pkg/repos
|
||||||
required: false
|
required: false
|
||||||
author: bleader
|
author: bleader
|
||||||
notes:
|
notes:
|
||||||
|
@ -68,6 +71,7 @@ EXAMPLES = '''
|
||||||
import json
|
import json
|
||||||
import shlex
|
import shlex
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def query_package(module, pkgin_path, name):
|
def query_package(module, pkgin_path, name):
|
||||||
|
@ -79,6 +83,22 @@ def query_package(module, pkgin_path, name):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def pkgng_older_than(module, pkgin_path, compare_version):
|
||||||
|
|
||||||
|
rc, out, err = module.run_command("%s -v" % pkgin_path)
|
||||||
|
version = map(lambda x: int(x), re.split(r'[\._]', out))
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
new_pkgng = True
|
||||||
|
while compare_version[i] == version[i]:
|
||||||
|
i += 1
|
||||||
|
if i == min(len(compare_version), len(version)):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if compare_version[i] > version[i]:
|
||||||
|
new_pkgng = False
|
||||||
|
return not new_pkgng
|
||||||
|
|
||||||
|
|
||||||
def remove_packages(module, pkgin_path, packages):
|
def remove_packages(module, pkgin_path, packages):
|
||||||
|
|
||||||
|
@ -108,11 +128,18 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
|
||||||
|
|
||||||
install_c = 0
|
install_c = 0
|
||||||
|
|
||||||
if pkgsite != "":
|
# as of pkg-1.1.4, PACKAGESITE is deprecated in favor of repository definitions
|
||||||
pkgsite="PACKAGESITE=%s" % (pkgsite)
|
# in /usr/local/etc/pkg/repos
|
||||||
|
old_pkgng = pkgng_older_than(module, pkgin_path, [1, 1, 4])
|
||||||
|
|
||||||
|
if old_pkgng and (pkgsite != ""):
|
||||||
|
pkgsite = "PACKAGESITE=%s" % (pkgsite)
|
||||||
|
|
||||||
if not module.check_mode and cached == "no":
|
if not module.check_mode and cached == "no":
|
||||||
|
if old_pkgng:
|
||||||
rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgin_path))
|
rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgin_path))
|
||||||
|
else:
|
||||||
|
rc, out, err = module.run_command("%s update" % (pkgin_path))
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="Could not update catalogue")
|
module.fail_json(msg="Could not update catalogue")
|
||||||
|
|
||||||
|
@ -121,7 +148,10 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
|
if old_pkgng:
|
||||||
rc, out, err = module.run_command("%s %s install -g -U -y %s" % (pkgsite, pkgin_path, package))
|
rc, out, err = module.run_command("%s %s install -g -U -y %s" % (pkgsite, pkgin_path, package))
|
||||||
|
else:
|
||||||
|
rc, out, err = module.run_command("%s install -r %s -g -U -y %s" % (pkgin_path, pkgsite, package))
|
||||||
|
|
||||||
if not module.check_mode and not query_package(module, pkgin_path, package):
|
if not module.check_mode and not query_package(module, pkgin_path, package):
|
||||||
module.fail_json(msg="failed to install %s: %s" % (package, out), stderr=err)
|
module.fail_json(msg="failed to install %s: %s" % (package, out), stderr=err)
|
||||||
|
|
Loading…
Reference in a new issue