mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Check for ConnectionError on change of config or commands (#41504)
This commit is contained in:
@@ -83,7 +83,10 @@ def run_commands(module, commands, check_rc=True):
|
||||
prompt = None
|
||||
answer = None
|
||||
|
||||
out = connection.get(command, prompt, answer)
|
||||
try:
|
||||
out = connection.get(command, prompt, answer)
|
||||
except ConnectionError as exc:
|
||||
module.fail_json(msg=to_text(exc))
|
||||
|
||||
try:
|
||||
out = to_text(out, errors='surrogate_or_strict')
|
||||
@@ -99,7 +102,10 @@ def run_commands(module, commands, check_rc=True):
|
||||
def load_config(module, commands, commit=False, comment=None):
|
||||
connection = get_connection(module)
|
||||
|
||||
out = connection.edit_config(commands)
|
||||
try:
|
||||
out = connection.edit_config(commands)
|
||||
except ConnectionError as exc:
|
||||
module.fail_json(msg=to_text(exc))
|
||||
|
||||
diff = None
|
||||
if module._diff:
|
||||
@@ -113,7 +119,7 @@ def load_config(module, commands, commit=False, comment=None):
|
||||
if commit:
|
||||
try:
|
||||
out = connection.commit(comment)
|
||||
except:
|
||||
except ConnectionError:
|
||||
connection.discard_changes()
|
||||
module.fail_json(msg='commit failed: %s' % out)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user