mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50: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
|
@ -131,7 +131,9 @@ backup_path:
|
|||
"""
|
||||
import re
|
||||
|
||||
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.vyos.vyos import load_config, get_config, run_commands
|
||||
from ansible.module_utils.network.vyos.vyos import vyos_argument_spec, get_connection
|
||||
|
||||
|
@ -208,7 +210,11 @@ def run(module, result):
|
|||
|
||||
# create loadable config that includes only the configuration updates
|
||||
connection = get_connection(module)
|
||||
response = connection.get_diff(candidate=candidate, running=config, diff_match=module.params['match'])
|
||||
try:
|
||||
response = connection.get_diff(candidate=candidate, running=config, diff_match=module.params['match'])
|
||||
except ConnectionError as exc:
|
||||
module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
||||
|
||||
commands = response.get('config_diff')
|
||||
sanitize_config(commands, result)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue