mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
dnf: fix TypeError when env/group failed
This commit is contained in:
parent
cafd064547
commit
de299ef77c
2 changed files with 11 additions and 23 deletions
|
@ -168,6 +168,7 @@ except ImportError:
|
|||
HAS_DNF = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.six import PY2
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
|
@ -349,7 +350,7 @@ def ensure(module, base, state, names, autoremove):
|
|||
for group_spec in (g.strip() for g in group_specs):
|
||||
group = base.comps.group_by_pattern(group_spec)
|
||||
if group:
|
||||
groups.append(group)
|
||||
groups.append(group.id)
|
||||
else:
|
||||
environment = base.comps.environment_by_pattern(group_spec)
|
||||
if environment:
|
||||
|
@ -365,18 +366,18 @@ def ensure(module, base, state, names, autoremove):
|
|||
# Install groups.
|
||||
for group in groups:
|
||||
try:
|
||||
base.group_install(group.id, dnf.const.GROUP_PACKAGE_TYPES)
|
||||
base.group_install(group, dnf.const.GROUP_PACKAGE_TYPES)
|
||||
except dnf.exceptions.Error as e:
|
||||
# In dnf 2.0 if all the mandatory packages in a group do
|
||||
# not install, an error is raised. We want to capture
|
||||
# this but still install as much as possible.
|
||||
failures.append((group, e))
|
||||
failures.append((group, to_native(e)))
|
||||
|
||||
for environment in environments:
|
||||
try:
|
||||
base.environment_install(environment, dnf.const.GROUP_PACKAGE_TYPES)
|
||||
except dnf.exceptions.Error as e:
|
||||
failures.append((group, e))
|
||||
failures.append((environment, to_native(e)))
|
||||
|
||||
# Install packages.
|
||||
for pkg_spec in pkg_specs:
|
||||
|
@ -389,12 +390,12 @@ def ensure(module, base, state, names, autoremove):
|
|||
for group in groups:
|
||||
try:
|
||||
try:
|
||||
base.group_upgrade(group.id)
|
||||
base.group_upgrade(group)
|
||||
except dnf.exceptions.CompsError:
|
||||
# If not already installed, try to install.
|
||||
base.group_install(group.id, dnf.const.GROUP_PACKAGE_TYPES)
|
||||
base.group_install(group, dnf.const.GROUP_PACKAGE_TYPES)
|
||||
except dnf.exceptions.Error as e:
|
||||
failures.append((group, e))
|
||||
failures.append((group, to_native(e)))
|
||||
|
||||
for environment in environments:
|
||||
try:
|
||||
|
@ -402,9 +403,9 @@ def ensure(module, base, state, names, autoremove):
|
|||
base.environment_upgrade(environment)
|
||||
except dnf.exceptions.CompsError:
|
||||
# If not already installed, try to install.
|
||||
base.environment_install(group, dnf.const.GROUP_PACKAGE_TYPES)
|
||||
base.environment_install(environment, dnf.const.GROUP_PACKAGE_TYPES)
|
||||
except dnf.exceptions.Error as e:
|
||||
failures.append((group, e))
|
||||
failures.append((environment, to_native(e)))
|
||||
|
||||
for pkg_spec in pkg_specs:
|
||||
# best effort causes to install the latest package
|
||||
|
@ -423,7 +424,7 @@ def ensure(module, base, state, names, autoremove):
|
|||
|
||||
for group in groups:
|
||||
try:
|
||||
base.group_remove(group.id)
|
||||
base.group_remove(group)
|
||||
except dnf.exceptions.CompsError:
|
||||
# Group is already uninstalled.
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue