YAML representer for VarsWithSources (#68525)
This commit is contained in:
parent
0f7f4e7b61
commit
6dbfd73174
3 changed files with 16 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- Add yaml representer for VarsWithSources (https://github.com/ansible/ansible/pull/68525).
|
|
@ -26,6 +26,7 @@ from ansible.module_utils.common.yaml import SafeDumper
|
|||
from ansible.parsing.yaml.objects import AnsibleUnicode, AnsibleSequence, AnsibleMapping, AnsibleVaultEncryptedUnicode
|
||||
from ansible.utils.unsafe_proxy import AnsibleUnsafeText, AnsibleUnsafeBytes
|
||||
from ansible.vars.hostvars import HostVars, HostVarsVars
|
||||
from ansible.vars.manager import VarsWithSources
|
||||
|
||||
|
||||
class AnsibleDumper(SafeDumper):
|
||||
|
@ -83,6 +84,11 @@ AnsibleDumper.add_representer(
|
|||
represent_hostvars,
|
||||
)
|
||||
|
||||
AnsibleDumper.add_representer(
|
||||
VarsWithSources,
|
||||
represent_hostvars,
|
||||
)
|
||||
|
||||
AnsibleDumper.add_representer(
|
||||
AnsibleSequence,
|
||||
yaml.representer.SafeRepresenter.represent_list,
|
||||
|
|
|
@ -19,6 +19,7 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import io
|
||||
import yaml
|
||||
|
||||
from units.compat import unittest
|
||||
from ansible.parsing import vault
|
||||
|
@ -29,6 +30,7 @@ from ansible.utils.unsafe_proxy import AnsibleUnsafeText, AnsibleUnsafeBytes
|
|||
|
||||
from units.mock.yaml_helper import YamlTestUtils
|
||||
from units.mock.vault_helper import TextVaultSecret
|
||||
from ansible.vars.manager import VarsWithSources
|
||||
|
||||
|
||||
class TestAnsibleDumper(unittest.TestCase, YamlTestUtils):
|
||||
|
@ -101,3 +103,9 @@ class TestAnsibleDumper(unittest.TestCase, YamlTestUtils):
|
|||
data_from_yaml = loader.get_single_data()
|
||||
|
||||
self.assertEqual(u_text, data_from_yaml)
|
||||
|
||||
def test_vars_with_sources(self):
|
||||
try:
|
||||
self._dump_string(VarsWithSources(), dumper=self.dumper)
|
||||
except yaml.representer.RepresenterError:
|
||||
self.fail("Dump VarsWithSources raised RepresenterError unexpectedly!")
|
||||
|
|
Loading…
Reference in a new issue