mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
zypper_repository: Proper failure when python-xml is missing (#939)
* Proper error when python-xml is missing * use missing_required_lib to output error * Add changelog
This commit is contained in:
parent
ba5b86cf4a
commit
09d89da0ab
2 changed files with 15 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- zypper_repository - proper failure when python-xml is missing (https://github.com/ansible-collections/community.general/pull/939).
|
|
@ -123,9 +123,19 @@ EXAMPLES = '''
|
|||
runrefresh: yes
|
||||
'''
|
||||
|
||||
import traceback
|
||||
|
||||
XML_IMP_ERR = None
|
||||
try:
|
||||
from xml.dom.minidom import parseString as parseXML
|
||||
HAS_XML = True
|
||||
except ImportError:
|
||||
XML_IMP_ERR = traceback.format_exc()
|
||||
HAS_XML = False
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck']
|
||||
|
@ -143,7 +153,8 @@ def _parse_repos(module):
|
|||
"""parses the output of zypper --xmlout repos and return a parse repo dictionary"""
|
||||
cmd = _get_cmd('--xmlout', 'repos')
|
||||
|
||||
from xml.dom.minidom import parseString as parseXML
|
||||
if not HAS_XML:
|
||||
module.fail_json(msg=missing_required_lib("python-xml"), exception=XML_IMP_ERR)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
if rc == 0:
|
||||
repos = []
|
||||
|
|
Loading…
Reference in a new issue