mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Fix netconf module and plugin issues (#45140)
* Fix netconf netconf issues * Identifier is optional for get_schema api * Fix dispatch api mandatory argument check * Add save option handling to copy config from target datastore to startup datastore if supported * Validate config in check-mode or if validate option set to true * Copy config if check-mode is not enabled
This commit is contained in:
parent
177fbea351
commit
455dfbe732
2 changed files with 12 additions and 11 deletions
|
@ -100,7 +100,8 @@ options:
|
|||
version_added: "2.7"
|
||||
save:
|
||||
description:
|
||||
- The C(save) argument instructs the module to save the running-config to the startup-config if changed.
|
||||
- The C(save) argument instructs the module to save the configuration in C(target) datastore to the
|
||||
startup-config if changed and if :startup capability is supported by Netconf server.
|
||||
default: false
|
||||
version_added: "2.4"
|
||||
backup:
|
||||
|
@ -275,6 +276,7 @@ def main():
|
|||
confirm_commit = module.params['confirm_commit']
|
||||
confirm = module.params['confirm']
|
||||
validate = module.params['validate']
|
||||
save = module.params['save']
|
||||
|
||||
conn = Connection(module._socket_path)
|
||||
capabilities = get_capabilities(module)
|
||||
|
@ -298,10 +300,10 @@ def main():
|
|||
module.fail_json(msg='neither :candidate nor :writable-running are supported by this netconf server')
|
||||
|
||||
# Netconf server capability validation against input options
|
||||
if module.params['save'] and not supports_startup:
|
||||
module.fail_json(msg='cannot copy <running/> to <startup/>, while :startup is not supported')
|
||||
if save and not supports_startup:
|
||||
module.fail_json(msg='cannot copy <%s/> to <startup/>, while :startup is not supported' % target)
|
||||
|
||||
if module.params['confirm_commit'] and not operations.get('supports_confirm_commit', False):
|
||||
if confirm_commit and not operations.get('supports_confirm_commit', False):
|
||||
module.fail_json(msg='confirm commit is not supported by Netconf server')
|
||||
|
||||
if confirm_commit or (confirm > 0) and not operations.get('supports_confirm_commit', False):
|
||||
|
@ -329,8 +331,7 @@ def main():
|
|||
before = to_text(response, errors='surrogate_then_replace').strip()
|
||||
result['__backup__'] = before.strip()
|
||||
if validate:
|
||||
if not module.check_mode:
|
||||
conn.validate(target)
|
||||
conn.validate(target)
|
||||
if source:
|
||||
if not module.check_mode:
|
||||
conn.copy(source, target)
|
||||
|
@ -377,8 +378,10 @@ def main():
|
|||
if sanitized_before != sanitized_after:
|
||||
result['changed'] = True
|
||||
|
||||
if module._diff:
|
||||
if result['changed']:
|
||||
if result['changed']:
|
||||
if save and not module.check_mode:
|
||||
conn.copy_config(target, 'startup')
|
||||
if module._diff:
|
||||
result['diff'] = {'before': sanitized_before, 'after': sanitized_after}
|
||||
|
||||
except ConnectionError as e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue