mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-07 08:54:01 -07:00
Handle ConnectionError exception in network modules (#43353)
* Handle ConnectionError exception in network modules * Catch ConnectionError expection and fail module in case expection is raised. * Fix CI failure
This commit is contained in:
parent
a44adc1dc9
commit
21dcaa4349
13 changed files with 241 additions and 117 deletions
|
@ -138,7 +138,9 @@ from functools import partial
|
|||
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.connection import ConnectionError
|
||||
from ansible.module_utils.network.common.utils import remove_default_spec
|
||||
from ansible.module_utils.network.junos.junos import junos_argument_spec, get_connection, tostring
|
||||
from ansible.module_utils.network.junos.junos import commit_configuration, discard_changes
|
||||
|
@ -160,7 +162,11 @@ def handle_purge(module, want):
|
|||
login = SubElement(element, 'login')
|
||||
|
||||
conn = get_connection(module)
|
||||
reply = conn.execute_rpc(tostring(Element('get-configuration')), ignore_warning=False)
|
||||
try:
|
||||
reply = conn.execute_rpc(tostring(Element('get-configuration')), ignore_warning=False)
|
||||
except ConnectionError as exc:
|
||||
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
||||
|
||||
users = reply.xpath('configuration/system/login/user/name')
|
||||
if users:
|
||||
for item in users:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue