|
|
@ -75,6 +75,13 @@ options:
|
|
|
|
default: auto
|
|
|
|
default: auto
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
version_added: "2.4"
|
|
|
|
version_added: "2.4"
|
|
|
|
|
|
|
|
save:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- The C(save) argument instructs the module to save the running-
|
|
|
|
|
|
|
|
config to the startup-config if changed.
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: false
|
|
|
|
|
|
|
|
version_added: "2.4"
|
|
|
|
username:
|
|
|
|
username:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the username to authenticate with
|
|
|
|
- the username to authenticate with
|
|
|
@ -86,7 +93,16 @@ options:
|
|
|
|
xml:
|
|
|
|
xml:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the XML content to send to the device
|
|
|
|
- the XML content to send to the device
|
|
|
|
required: true
|
|
|
|
required: false
|
|
|
|
|
|
|
|
src:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Specifies the source path to the xml file that contains the configuration
|
|
|
|
|
|
|
|
or configuration template to load. The path to the source file can
|
|
|
|
|
|
|
|
either be the full path on the Ansible control host or a relative
|
|
|
|
|
|
|
|
path from the playbook or role root directory. This argument is mutually
|
|
|
|
|
|
|
|
exclusive with I(xml).
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
version_added: "2.4"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements:
|
|
|
|
requirements:
|
|
|
@ -185,26 +201,35 @@ def main():
|
|
|
|
hostkey_verify=dict(type='bool', default=True),
|
|
|
|
hostkey_verify=dict(type='bool', default=True),
|
|
|
|
allow_agent=dict(type='bool', default=True),
|
|
|
|
allow_agent=dict(type='bool', default=True),
|
|
|
|
look_for_keys=dict(type='bool', default=True),
|
|
|
|
look_for_keys=dict(type='bool', default=True),
|
|
|
|
datastore=dict(type='str', default='auto'),
|
|
|
|
datastore=dict(choices=['auto', 'candidate', 'running'], default='auto'),
|
|
|
|
|
|
|
|
save=dict(type='bool', default=False),
|
|
|
|
username=dict(type='str', required=True, no_log=True),
|
|
|
|
username=dict(type='str', required=True, no_log=True),
|
|
|
|
password=dict(type='str', required=True, no_log=True),
|
|
|
|
password=dict(type='str', required=True, no_log=True),
|
|
|
|
xml=dict(type='str', required=True),
|
|
|
|
xml=dict(type='str', required=False),
|
|
|
|
)
|
|
|
|
src=dict(type='path', required=False),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
mutually_exclusive=[('xml', 'src')]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if not HAS_NCCLIENT:
|
|
|
|
if not HAS_NCCLIENT:
|
|
|
|
module.fail_json(msg='could not import the python library '
|
|
|
|
module.fail_json(msg='could not import the python library '
|
|
|
|
'ncclient required by this module')
|
|
|
|
'ncclient required by this module')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (module.params['src']):
|
|
|
|
|
|
|
|
config_xml = str(module.params['src'])
|
|
|
|
|
|
|
|
elif module.params['xml']:
|
|
|
|
|
|
|
|
config_xml = str(module.params['xml'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
module.fail_json(msg='Option src or xml must be provided')
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
xml.dom.minidom.parseString(module.params['xml'])
|
|
|
|
xml.dom.minidom.parseString(config_xml)
|
|
|
|
|
|
|
|
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
e = get_exception()
|
|
|
|
e = get_exception()
|
|
|
|
module.fail_json(
|
|
|
|
module.fail_json(
|
|
|
|
msg='error parsing XML: ' +
|
|
|
|
msg='error parsing XML: ' + str(e)
|
|
|
|
str(e)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nckwargs = dict(
|
|
|
|
nckwargs = dict(
|
|
|
|
host=module.params['host'],
|
|
|
|
host=module.params['host'],
|
|
|
@ -215,7 +240,6 @@ def main():
|
|
|
|
username=module.params['username'],
|
|
|
|
username=module.params['username'],
|
|
|
|
password=module.params['password'],
|
|
|
|
password=module.params['password'],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
retkwargs = dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
m = ncclient.manager.connect(**nckwargs)
|
|
|
|
m = ncclient.manager.connect(**nckwargs)
|
|
|
@ -226,11 +250,12 @@ def main():
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
e = get_exception()
|
|
|
|
e = get_exception()
|
|
|
|
module.fail_json(
|
|
|
|
module.fail_json(
|
|
|
|
msg='error connecting to the device: ' +
|
|
|
|
msg='error connecting to the device: ' + str(e)
|
|
|
|
str(e)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
retkwargs = dict()
|
|
|
|
retkwargs['server_capabilities'] = list(m.server_capabilities)
|
|
|
|
retkwargs['server_capabilities'] = list(m.server_capabilities)
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['datastore'] == 'candidate':
|
|
|
|
if module.params['datastore'] == 'candidate':
|
|
|
|
if ':candidate' in m.server_capabilities:
|
|
|
|
if ':candidate' in m.server_capabilities:
|
|
|
|
datastore = 'candidate'
|
|
|
|
datastore = 'candidate'
|
|
|
@ -255,28 +280,39 @@ def main():
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
m.close_session()
|
|
|
|
m.close_session()
|
|
|
|
module.fail_json(
|
|
|
|
module.fail_json(
|
|
|
|
msg='neither :candidate nor :writable-running are supported by this netconf server')
|
|
|
|
msg='neither :candidate nor :writable-running are supported by this netconf server'
|
|
|
|
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
m.close_session()
|
|
|
|
m.close_session()
|
|
|
|
module.fail_json(
|
|
|
|
module.fail_json(
|
|
|
|
msg=module.params['datastore'] +
|
|
|
|
msg=module.params['datastore'] + ' datastore is not supported by this ansible module'
|
|
|
|
' datastore is not supported by this ansible module')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['save']:
|
|
|
|
|
|
|
|
if ':startup' not in m.server_capabilities:
|
|
|
|
|
|
|
|
module.fail_json(
|
|
|
|
|
|
|
|
msg='cannot copy <running/> to <startup/>, while :startup is not supported'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
changed = netconf_edit_config(
|
|
|
|
changed = netconf_edit_config(
|
|
|
|
m=m,
|
|
|
|
m=m,
|
|
|
|
xml=module.params['xml'],
|
|
|
|
xml=config_xml,
|
|
|
|
commit=True,
|
|
|
|
commit=True,
|
|
|
|
retkwargs=retkwargs,
|
|
|
|
retkwargs=retkwargs,
|
|
|
|
datastore=datastore,
|
|
|
|
datastore=datastore,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if changed and module.params['save']:
|
|
|
|
|
|
|
|
m.copy_config(source="running", target="startup")
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
e = get_exception()
|
|
|
|
e = get_exception()
|
|
|
|
module.fail_json(msg='error editing configuration: ' + str(e))
|
|
|
|
module.fail_json(
|
|
|
|
|
|
|
|
msg='error editing configuration: ' + str(e)
|
|
|
|
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
m.close_session()
|
|
|
|
m.close_session()
|
|
|
|
module.exit_json(changed=changed, **retkwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(changed=changed, **retkwargs)
|
|
|
|
|
|
|
|
|
|
|
|
# import module snippets
|
|
|
|
# import module snippets
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|