summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <privateip@users.noreply.github.com>2017-03-13 07:27:45 -0400
committerGitHub <noreply@github.com>2017-03-13 07:27:45 -0400
commit39c38bf30d0224ee94b561fb73bc474e9bdea92a (patch)
treee525eec0d266d4cdea638058b6ad04f1381f3940
parentb3004e19a5879d4d453337617a7c09a8f3a4fc6d (diff)
downloadansible-39c38bf30d0224ee94b561fb73bc474e9bdea92a.tar.gz
fixes candidate var type in junos shared lib (#22551)
* candidate var can now be string, list or element * fixes minor bug in junos_template for backup argument * disabled invalid integration test for junos_template
-rw-r--r--lib/ansible/module_utils/junos.py13
-rw-r--r--lib/ansible/modules/network/junos/_junos_template.py21
-rw-r--r--test/integration/targets/junos_template/tests/netconf/force.disabled (renamed from test/integration/targets/junos_template/tests/netconf/force.yaml)2
3 files changed, 19 insertions, 17 deletions
diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py
index accec56fc3..0646d70630 100644
--- a/lib/ansible/module_utils/junos.py
+++ b/lib/ansible/module_utils/junos.py
@@ -24,7 +24,7 @@ from ansible.module_utils.basic import env_fallback
from ansible.module_utils.netconf import send_request, children
from ansible.module_utils.netconf import discard_changes, validate
from ansible.module_utils.network_common import to_list
-from ansible.module_utils.connection import exec_command
+from ansible.module_utils.six import string_types
ACTIONS = frozenset(['merge', 'override', 'replace', 'update', 'set'])
JSON_ACTIONS = frozenset(['merge', 'override', 'update'])
@@ -88,10 +88,13 @@ def load_configuration(module, candidate=None, action='merge', rollback=None, fo
if action == 'set':
cfg = SubElement(obj, 'configuration-set')
- cfg.text = '\n'.join(candidate)
else:
cfg = SubElement(obj, lookup[format])
- cfg.text = '\n'.join(candidate)
+
+ if isinstance(candidate, string_types):
+ cfg.text = candidate
+ else:
+ cfg.append(candidate)
return send_request(module, obj)
@@ -138,6 +141,7 @@ def locked_config(module):
unlock_configuration(module)
def get_diff(module):
+
reply = get_configuration(module, compare=True, format='text')
output = reply.find('.//configuration-output')
if output is not None:
@@ -147,6 +151,9 @@ def load_config(module, candidate, action='merge', commit=False, format='xml',
comment=None, confirm=False, confirm_timeout=None):
with locked_config(module):
+ if isinstance(candidate, list):
+ candidate = '\n'.join(candidate)
+
reply = load_configuration(module, candidate, action=action, format=format)
validate(module)
diff --git a/lib/ansible/modules/network/junos/_junos_template.py b/lib/ansible/modules/network/junos/_junos_template.py
index 5cbb87a26c..bd6c85f64c 100644
--- a/lib/ansible/modules/network/junos/_junos_template.py
+++ b/lib/ansible/modules/network/junos/_junos_template.py
@@ -113,19 +113,12 @@ EXAMPLES = """
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.junos import check_args, junos_argument_spec
-from ansible.module_utils.junos import get_configuration, load
+from ansible.module_utils.junos import get_configuration, load_config
from ansible.module_utils.six import text_type
USE_PERSISTENT_CONNECTION = True
DEFAULT_COMMENT = 'configured by junos_template'
-def check_transport(module):
- transport = (module.params['provider'] or {}).get('transport')
-
- if transport == 'netconf':
- module.fail_json(msg='junos_template module is only supported over cli transport')
-
-
def main():
argument_spec = dict(
@@ -133,7 +126,7 @@ def main():
confirm=dict(default=0, type='int'),
comment=dict(default=DEFAULT_COMMENT),
action=dict(default='merge', choices=['merge', 'overwrite', 'replace']),
- config_format=dict(choices=['text', 'set', 'xml']),
+ config_format=dict(choices=['text', 'set', 'xml'], default='text'),
backup=dict(default=False, type='bool'),
)
@@ -142,8 +135,6 @@ def main():
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
- check_transport(module)
-
warnings = list()
check_args(module, warnings)
@@ -161,9 +152,13 @@ def main():
"set per junos-pyez documentation")
if module.params['backup']:
- result['__backup__'] = text_type(get_configuration(module))
+ reply = get_configuration(module, format='set')
+ match = reply.find('.//configuration-set')
+ if match is None:
+ module.fail_json(msg='unable to retrieve device configuration')
+ result['__backup__'] = str(match.text).strip()
- diff = load(module, src, action=action, commit=commit, format=fmt)
+ diff = load_config(module, src, action=action, commit=commit, format=fmt)
if diff:
result['changed'] = True
if module._diff:
diff --git a/test/integration/targets/junos_template/tests/netconf/force.yaml b/test/integration/targets/junos_template/tests/netconf/force.disabled
index 05496b143e..106eab3f17 100644
--- a/test/integration/targets/junos_template/tests/netconf/force.yaml
+++ b/test/integration/targets/junos_template/tests/netconf/force.disabled
@@ -22,7 +22,7 @@
- name: check basic config template idempotent
junos_template:
- src: basic/config.j2
+ src: basic/config-update.j2
action: replace
provider: "{{ netconf }}"
register: result