Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall-back to show configuration on old IOSXR devices #22900

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ansible/module_utils/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def run_commands(module, commands, check_rc=True):
responses.append(out)
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')
if rc != 0:
Expand All @@ -106,6 +106,13 @@ def load_config(module, commands, commit=False, replace=False, comment=None):
module.fail_json(msg=err, commands=commands, rc=rc)

rc, diff, err = exec_command(module, 'show commit changes diff')
if rc != 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would assert that if config diff isn't supported just return None and raise an ansible warning if module diff was asked for and the platform doesnt support it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is we set the task to 'changed' only if diff is not None in the run module function, but we may have changed the device even if the diff collected with 'show configuration' doesn't provide +/- changes.

I'm just putting the warning to let the user know that the diff may be bogus if old device but still have a consistent changed status.

# 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:
cmd = 'commit'
if comment:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/iosxr/_iosxr_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def main():
commands = [c.strip() for c in str(candidate).split('\n')]

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['updates'] = commands
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/network/iosxr/iosxr_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ def run(module, result):

result['commands'] = commands

diff = load_config(module, commands, not check_mode,
replace_config, comment)
diff = load_config(module, commands, result['warnings'],
not check_mode, replace_config, comment)
if diff:
result['diff'] = dict(prepared=diff)
result['changed'] = True
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/iosxr/iosxr_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def main():

if commands:
if not module.check_mode:
load_config(module, commands, commit=True)
load_config(module, commands, result['warnings'], commit=True)
result['changed'] = True

module.exit_json(**result)
Expand Down