|
@@ -24,11 +24,19 @@ from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
|
from ansible.module_utils.six import string_types
|
|
|
|
|
|
-IMPORT_EXCEPTION = None
|
|
|
+YUM_IMPORT_EXCEPTION = None
|
|
|
+DNF_IMPORT_EXCEPTION = None
|
|
|
+PKG_MGR = None
|
|
|
try:
|
|
|
import yum
|
|
|
+ PKG_MGR = "yum"
|
|
|
except ImportError as err:
|
|
|
- IMPORT_EXCEPTION = err
|
|
|
+ YUM_IMPORT_EXCEPTION = err
|
|
|
+try:
|
|
|
+ import dnf
|
|
|
+ PKG_MGR = "dnf"
|
|
|
+except ImportError as err:
|
|
|
+ DNF_IMPORT_EXCEPTION = err
|
|
|
|
|
|
|
|
|
class AosVersionException(Exception):
|
|
@@ -47,8 +55,11 @@ def main():
|
|
|
supports_check_mode=True
|
|
|
)
|
|
|
|
|
|
- if IMPORT_EXCEPTION:
|
|
|
- module.fail_json(msg="aos_version module could not import yum: %s" % IMPORT_EXCEPTION)
|
|
|
+ if YUM_IMPORT_EXCEPTION and DNF_IMPORT_EXCEPTION:
|
|
|
+ module.fail_json(
|
|
|
+ msg="aos_version module could not import yum or dnf: %s %s" %
|
|
|
+ (YUM_IMPORT_EXCEPTION, DNF_IMPORT_EXCEPTION)
|
|
|
+ )
|
|
|
|
|
|
|
|
|
package_list = module.params['package_list']
|
|
@@ -83,9 +94,6 @@ def _to_dict(pkg_list):
|
|
|
|
|
|
|
|
|
def _retrieve_available_packages(expected_pkgs):
|
|
|
-
|
|
|
- yb = yum.YumBase()
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -94,17 +102,34 @@ def _retrieve_available_packages(expected_pkgs):
|
|
|
|
|
|
|
|
|
|
|
|
- yb.conf.disable_excludes = ['all']
|
|
|
|
|
|
- try:
|
|
|
- pkgs = yb.pkgSack.returnPackages(patterns=expected_pkgs)
|
|
|
- except yum.Errors.PackageSackError as excinfo:
|
|
|
-
|
|
|
- raise AosVersionException('\n'.join([
|
|
|
- 'Unable to find any OpenShift packages.',
|
|
|
- 'Check your subscription and repo settings.',
|
|
|
- str(excinfo),
|
|
|
- ]))
|
|
|
+ if PKG_MGR == "yum":
|
|
|
+
|
|
|
+ yb = yum.YumBase()
|
|
|
+
|
|
|
+ yb.conf.disable_excludes = ['all']
|
|
|
+
|
|
|
+ try:
|
|
|
+ pkgs = yb.pkgSack.returnPackages(patterns=expected_pkgs)
|
|
|
+ except yum.Errors.PackageSackError as excinfo:
|
|
|
+
|
|
|
+ raise AosVersionException('\n'.join([
|
|
|
+ 'Unable to find any OpenShift packages.',
|
|
|
+ 'Check your subscription and repo settings.',
|
|
|
+ str(excinfo),
|
|
|
+ ]))
|
|
|
+ elif PKG_MGR == "dnf":
|
|
|
+ dbase = dnf.Base()
|
|
|
+
|
|
|
+ dbase.conf.disable_excludes = ['all']
|
|
|
+ dbase.read_all_repos()
|
|
|
+ dbase.fill_sack(load_system_repo=False, load_available_repos=True)
|
|
|
+
|
|
|
+ dquery = dbase.sack.query()
|
|
|
+ aquery = dquery.available()
|
|
|
+
|
|
|
+ pkgs = list(aquery.filter(name=expected_pkgs))
|
|
|
+
|
|
|
return pkgs
|
|
|
|
|
|
|