roll up of bug fixes for junos_config module (#4925)
* fixed docstring referencing old arguments * changed out lxml for xml library to avoid import errors * fixed issue when trying to confirm a commit will end up a NOOP * fixed issue for passing replace argument to load_config method
This commit is contained in:
parent
0acab8bd19
commit
82cf70e0f3
1 changed files with 23 additions and 20 deletions
|
@ -31,10 +31,10 @@ extends_documentation_fragment: junos
|
||||||
options:
|
options:
|
||||||
lines:
|
lines:
|
||||||
description:
|
description:
|
||||||
- The path to the config source. The source can be either a
|
- This argument takes a list of C(set) or C(delete) configuration
|
||||||
file with config or a template that will be merged during
|
lines to push into the remote device. Each line must start with
|
||||||
runtime. By default the task will search for the source
|
either C(set) or C(delete). This argument is mutually exclusive
|
||||||
file in role or playbook root folder in templates directory.
|
with the I(src) argument.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
src:
|
src:
|
||||||
|
@ -58,17 +58,6 @@ options:
|
||||||
default: null
|
default: null
|
||||||
choices: ['xml', 'set', 'text', 'json']
|
choices: ['xml', 'set', 'text', 'json']
|
||||||
version_added: "2.2"
|
version_added: "2.2"
|
||||||
update:
|
|
||||||
description:
|
|
||||||
- The I(update) argument controls how the configuration statements
|
|
||||||
are processed on the remote device. Valid choices for the I(update)
|
|
||||||
argument are I(merge) and I(replace). When the argument is set to
|
|
||||||
I(merge), the configuration changes are merged with the current
|
|
||||||
device active configuration.
|
|
||||||
required: false
|
|
||||||
default: merge
|
|
||||||
choices: ['merge', 'replace']
|
|
||||||
version_added: "2.2"
|
|
||||||
rollback:
|
rollback:
|
||||||
description:
|
description:
|
||||||
- The C(rollback) argument instructs the module to rollback the
|
- The C(rollback) argument instructs the module to rollback the
|
||||||
|
@ -159,6 +148,10 @@ vars:
|
||||||
junos_config:
|
junos_config:
|
||||||
zeroize: yes
|
zeroize: yes
|
||||||
provider: "{{ netconf }}"
|
provider: "{{ netconf }}"
|
||||||
|
|
||||||
|
- name: confirm a previous commit
|
||||||
|
junos_config:
|
||||||
|
provider: "{{ netconf }}"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN = """
|
RETURN = """
|
||||||
|
@ -168,12 +161,14 @@ backup_path:
|
||||||
type: path
|
type: path
|
||||||
sample: /playbooks/ansible/backup/config.2016-07-16@22:28:34
|
sample: /playbooks/ansible/backup/config.2016-07-16@22:28:34
|
||||||
"""
|
"""
|
||||||
import re
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from lxml import etree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
from ansible.module_utils.junos import NetworkModule, NetworkError
|
import ansible.module_utils.junos
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import get_exception
|
||||||
|
from ansible.module_utils.network import NetworkModule, NetworkError
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT = 'configured by junos_config'
|
DEFAULT_COMMENT = 'configured by junos_config'
|
||||||
|
@ -187,9 +182,9 @@ def guess_format(config):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
etree.fromstring(config)
|
ElementTree.fromstring(config)
|
||||||
return 'xml'
|
return 'xml'
|
||||||
except etree.XMLSyntaxError:
|
except ElementTree.ParseError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if config.startswith('set') or config.startswith('delete'):
|
if config.startswith('set') or config.startswith('delete'):
|
||||||
|
@ -203,6 +198,7 @@ def load_config(module, result):
|
||||||
kwargs = dict()
|
kwargs = dict()
|
||||||
kwargs['comment'] = module.params['comment']
|
kwargs['comment'] = module.params['comment']
|
||||||
kwargs['confirm'] = module.params['confirm']
|
kwargs['confirm'] = module.params['confirm']
|
||||||
|
kwargs['replace'] = module.params['replace']
|
||||||
kwargs['commit'] = not module.check_mode
|
kwargs['commit'] = not module.check_mode
|
||||||
|
|
||||||
if module.params['src']:
|
if module.params['src']:
|
||||||
|
@ -234,11 +230,18 @@ def zeroize_config(module, result):
|
||||||
module.cli.run_commands('request system zeroize')
|
module.cli.run_commands('request system zeroize')
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
||||||
|
def confirm_config(module, result):
|
||||||
|
if not module.check_mode:
|
||||||
|
module.connection.commit_config()
|
||||||
|
result['changed'] = True
|
||||||
|
|
||||||
def run(module, result):
|
def run(module, result):
|
||||||
if module.params['rollback']:
|
if module.params['rollback']:
|
||||||
return rollback_config(module, result)
|
return rollback_config(module, result)
|
||||||
elif module.params['zeroize']:
|
elif module.params['zeroize']:
|
||||||
return zeroize_config(module, result)
|
return zeroize_config(module, result)
|
||||||
|
elif not any((module.params['src'], module.params['lines'])):
|
||||||
|
return confirm_config(module, result)
|
||||||
else:
|
else:
|
||||||
return load_config(module, result)
|
return load_config(module, result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue