mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
Fall-back to show configuration on old IOSXR devices (#22900)
In old IOSXR versions, 'show commit changes diff' does not work. Fall-back to 'show configuration' if that command fails so execution can move forward. Fixes #22235
This commit is contained in:
parent
6c101087ac
commit
cc7e09451a
4 changed files with 12 additions and 5 deletions
|
@ -85,7 +85,7 @@ def run_commands(module, commands, check_rc=True):
|
||||||
responses.append(out)
|
responses.append(out)
|
||||||
return responses
|
return responses
|
||||||
|
|
||||||
def load_config(module, commands, commit=False, replace=False, comment=None):
|
def load_config(module, commands, warnings, commit=False, replace=False, comment=None):
|
||||||
|
|
||||||
rc, out, err = exec_command(module, 'configure terminal')
|
rc, out, err = exec_command(module, 'configure terminal')
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
|
@ -106,6 +106,13 @@ def load_config(module, commands, commit=False, replace=False, comment=None):
|
||||||
module.fail_json(msg=err, commands=commands, rc=rc)
|
module.fail_json(msg=err, commands=commands, rc=rc)
|
||||||
|
|
||||||
rc, diff, err = exec_command(module, 'show commit changes diff')
|
rc, diff, err = exec_command(module, 'show commit changes diff')
|
||||||
|
if rc != 0:
|
||||||
|
# If we failed, maybe we are in an old version so
|
||||||
|
# we run show configuration instead
|
||||||
|
rc, diff, err = exec_command(module, 'show configuration')
|
||||||
|
if module._diff:
|
||||||
|
warnings.append('device platform does not support config diff')
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
cmd = 'commit'
|
cmd = 'commit'
|
||||||
if comment:
|
if comment:
|
||||||
|
|
|
@ -146,7 +146,7 @@ def main():
|
||||||
commands = [c.strip() for c in str(candidate).split('\n')]
|
commands = [c.strip() for c in str(candidate).split('\n')]
|
||||||
|
|
||||||
if commands:
|
if commands:
|
||||||
load_config(module, commands, not module.check_mode)
|
load_config(module, commands, result['warnings'], not module.check_mode)
|
||||||
result['changed'] = not module.check_mode
|
result['changed'] = not module.check_mode
|
||||||
|
|
||||||
result['updates'] = commands
|
result['updates'] = commands
|
||||||
|
|
|
@ -240,8 +240,8 @@ def run(module, result):
|
||||||
|
|
||||||
result['commands'] = commands
|
result['commands'] = commands
|
||||||
|
|
||||||
diff = load_config(module, commands, not check_mode,
|
diff = load_config(module, commands, result['warnings'],
|
||||||
replace_config, comment)
|
not check_mode, replace_config, comment)
|
||||||
if diff:
|
if diff:
|
||||||
result['diff'] = dict(prepared=diff)
|
result['diff'] = dict(prepared=diff)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
|
@ -243,7 +243,7 @@ def main():
|
||||||
|
|
||||||
if commands:
|
if commands:
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
load_config(module, commands, commit=True)
|
load_config(module, commands, result['warnings'], commit=True)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue