Merge "Fix dumping hostvars to yaml from overrides"
This commit is contained in:
commit
c5d588fce9
@ -38,6 +38,7 @@ from ansible.plugins.action import ActionBase
|
|||||||
from ansible.module_utils._text import to_bytes, to_text
|
from ansible.module_utils._text import to_bytes, to_text
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
|
from ansible.parsing.yaml.dumper import AnsibleDumper
|
||||||
|
|
||||||
|
|
||||||
CONFIG_TYPES = {
|
CONFIG_TYPES = {
|
||||||
@ -73,7 +74,7 @@ def _convert_2_string(item):
|
|||||||
return str(item)
|
return str(item)
|
||||||
|
|
||||||
|
|
||||||
class IDumper(yaml.SafeDumper):
|
class IDumper(AnsibleDumper):
|
||||||
def increase_indent(self, flow=False, indentless=False):
|
def increase_indent(self, flow=False, indentless=False):
|
||||||
return super(IDumper, self).increase_indent(flow, False)
|
return super(IDumper, self).increase_indent(flow, False)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
- name: Test config_template
|
- name: Test config_template
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
connection: local
|
connection: local
|
||||||
gather_facts: no
|
gather_facts: yes
|
||||||
tasks:
|
tasks:
|
||||||
# Test basic function of config_template
|
# Test basic function of config_template
|
||||||
- name: Template test INI template
|
- name: Template test INI template
|
||||||
@ -109,6 +109,27 @@
|
|||||||
that:
|
that:
|
||||||
- "(no_extend_file.content | b64decode) == (no_extend_file_expected.content | b64decode)"
|
- "(no_extend_file.content | b64decode) == (no_extend_file_expected.content | b64decode)"
|
||||||
|
|
||||||
|
# Test dumping hostvars using config overrides
|
||||||
|
- name: Template test YML template with hostvars override
|
||||||
|
config_template:
|
||||||
|
src: "{{ playbook_dir }}/templates/test.yml"
|
||||||
|
dest: "/tmp/test_hostvars.yml"
|
||||||
|
config_overrides: "{{ test_config_yml_hostvars_overrides }}"
|
||||||
|
config_type: "yaml"
|
||||||
|
- name: Read test_hostvars.yml
|
||||||
|
slurp:
|
||||||
|
src: /tmp/test_hostvars.yml
|
||||||
|
register: hostvars_file
|
||||||
|
- debug:
|
||||||
|
msg: "hostvars - {{ (hostvars_file.content | b64decode | from_yaml).test_hostvar }}"
|
||||||
|
- debug:
|
||||||
|
msg: "hostvars.expected - {{ test_config_yml_hostvars_overrides.test_hostvar }}"
|
||||||
|
- name: Compare files
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "((hostvars_file.content | b64decode | from_yaml).test_hostvar) == (test_config_yml_hostvars_overrides.test_hostvar)"
|
||||||
|
|
||||||
|
|
||||||
# Test content attribute with a dictionary input and config_type equal to 'json'
|
# Test content attribute with a dictionary input and config_type equal to 'json'
|
||||||
- name: Template test JSON template with content attribute
|
- name: Template test JSON template with content attribute
|
||||||
config_template:
|
config_template:
|
||||||
@ -165,3 +186,5 @@
|
|||||||
test_config_yml_overrides:
|
test_config_yml_overrides:
|
||||||
list_one:
|
list_one:
|
||||||
- four
|
- four
|
||||||
|
test_config_yml_hostvars_overrides:
|
||||||
|
test_hostvar: "{{ ansible_default_ipv4.address }}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user