
By default a list item in a JSON or YAML format will extend if a its already defined in the target template and a config_override using a list is being set for the existing "key". This change allows that functionality to be toggled on or off. The boolean option to enable list extension is ``list_extend``. To maintain the API this feature will remain True by default. Co-Authored-By: Travis Truman <travis_truman@cable.comcast.com> Change-Id: I97e06aef2cc778f048f3d6863fe61d10eddb8602 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
99 lines
3.3 KiB
YAML
99 lines
3.3 KiB
YAML
---
|
|
# Copyright 2016, Comcast Corp.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
- name: Test config_template
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: no
|
|
tasks:
|
|
# Test basic function of config_template
|
|
- name: Template test INI template
|
|
config_template:
|
|
src: "{{ playbook_dir }}/templates/test.ini"
|
|
dest: "/tmp/test.ini"
|
|
config_overrides: "{{ test_config_ini_overrides }}"
|
|
config_type: "ini"
|
|
|
|
- name: Read test.ini
|
|
slurp:
|
|
src: /tmp/test.ini
|
|
register: ini_file
|
|
- debug:
|
|
msg: "ini - {{ ini_file.content | b64decode }}"
|
|
- name: Validate output
|
|
assert:
|
|
that:
|
|
- "(lookup('ini', 'new_key section=DEFAULT file=/tmp/test.ini')) == 'new_value'"
|
|
- "(lookup('ini', 'baz section=foo file=/tmp/test.ini')) == 'bar'"
|
|
|
|
# Test list additions in config_template
|
|
- name: Template test YML template
|
|
config_template:
|
|
src: "{{ playbook_dir }}/templates/test.yml"
|
|
dest: "/tmp/test_extend.yml"
|
|
config_overrides: "{{ test_config_yml_overrides }}"
|
|
config_type: "yaml"
|
|
list_extend: True
|
|
|
|
- name: Read test_extend.yml
|
|
slurp:
|
|
src: /tmp/test_extend.yml
|
|
register: extend_file
|
|
- name: Read expected test_extend.yml
|
|
slurp:
|
|
src: "{{ playbook_dir }}/files/test_extend.yml.expected"
|
|
register: extend_file_expected
|
|
- debug:
|
|
msg: "extend - {{ extend_file.content | b64decode }}"
|
|
- debug:
|
|
msg: "extend.expected - {{ extend_file_expected.content | b64decode }}"
|
|
- name: Compare files
|
|
assert:
|
|
that:
|
|
- "(extend_file.content | b64decode) == (extend_file_expected.content | b64decode)"
|
|
|
|
# Test list replacement in config_template
|
|
- name: Template test YML template
|
|
config_template:
|
|
src: "{{ playbook_dir }}/templates/test.yml"
|
|
dest: "/tmp/test_no_extend.yml"
|
|
config_overrides: "{{ test_config_yml_overrides }}"
|
|
config_type: "yaml"
|
|
list_extend: False
|
|
- name: Read test_no_extend.yml
|
|
slurp:
|
|
src: /tmp/test_no_extend.yml
|
|
register: no_extend_file
|
|
- name: Read expected test_no_extend.yml
|
|
slurp:
|
|
src: "{{ playbook_dir }}/files/test_no_extend.yml.expected"
|
|
register: no_extend_file_expected
|
|
- debug:
|
|
msg: "no_extend - {{ no_extend_file.content | b64decode }}"
|
|
- debug:
|
|
msg: "no_extend.expected - {{ no_extend_file_expected.content | b64decode }}"
|
|
- name: Compare files
|
|
assert:
|
|
that:
|
|
- "(no_extend_file.content | b64decode) == (no_extend_file_expected.content | b64decode)"
|
|
vars:
|
|
test_config_ini_overrides:
|
|
DEFAULT:
|
|
new_key: "new_value"
|
|
foo:
|
|
baz: "bar"
|
|
test_config_yml_overrides:
|
|
list_one:
|
|
- four |