mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -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
|
@ -77,6 +77,8 @@ commands:
|
|||
"""
|
||||
import re
|
||||
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.connection import ConnectionError
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.junos.junos import junos_argument_spec, get_connection
|
||||
from ansible.module_utils.network.junos.junos import commit_configuration, discard_changes
|
||||
|
@ -146,9 +148,12 @@ def map_params_to_obj(module):
|
|||
|
||||
def load_config(module, config, commit=False):
|
||||
conn = get_connection(module)
|
||||
try:
|
||||
conn.edit_config(to_list(config) + ['top'])
|
||||
diff = conn.compare_configuration()
|
||||
except ConnectionError as exc:
|
||||
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
||||
|
||||
conn.edit_config(to_list(config) + ['top'])
|
||||
diff = conn.compare_configuration()
|
||||
if diff:
|
||||
if commit:
|
||||
commit_configuration(module)
|
||||
|
@ -156,7 +161,7 @@ def load_config(module, config, commit=False):
|
|||
else:
|
||||
discard_changes(module)
|
||||
|
||||
return str(diff).strip()
|
||||
return to_text(diff, errors='surrogate_then_replace').strip()
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue