Fix dumping hostvars to yaml from overrides
Using AnsibleDumper adds support for dumping the internal ansible data types that are used in hostvars. Fixes-Bug: #1707265 Change-Id: Ie59bbef31306cd3e99aa827db875922e17084e83
This commit is contained in:
parent
d7e23e1be8
commit
6d496d6c5b
@ -38,6 +38,7 @@ from ansible.plugins.action import ActionBase
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
from ansible import constants as C
|
||||
from ansible import errors
|
||||
from ansible.parsing.yaml.dumper import AnsibleDumper
|
||||
|
||||
|
||||
CONFIG_TYPES = {
|
||||
@ -73,7 +74,7 @@ def _convert_2_string(item):
|
||||
return str(item)
|
||||
|
||||
|
||||
class IDumper(yaml.SafeDumper):
|
||||
class IDumper(AnsibleDumper):
|
||||
def increase_indent(self, flow=False, indentless=False):
|
||||
return super(IDumper, self).increase_indent(flow, False)
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
- name: Test config_template
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: no
|
||||
gather_facts: yes
|
||||
tasks:
|
||||
# Test basic function of config_template
|
||||
- name: Template test INI template
|
||||
@ -109,6 +109,27 @@
|
||||
that:
|
||||
- "(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'
|
||||
- name: Template test JSON template with content attribute
|
||||
config_template:
|
||||
@ -165,3 +186,5 @@
|
||||
test_config_yml_overrides:
|
||||
list_one:
|
||||
- four
|
||||
test_config_yml_hostvars_overrides:
|
||||
test_hostvar: "{{ ansible_default_ipv4.address }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user