|
111 | 111 | '''
|
112 | 112 |
|
113 | 113 | import os
|
114 |
| -import yaml |
115 |
| - |
116 |
| -from jinja2 import Template |
117 |
| -from yaml.loader import SafeLoader |
118 | 114 |
|
119 | 115 | from ansible.errors import AnsibleParserError
|
120 | 116 | from ansible.module_utils._text import to_bytes, to_native, to_text
|
121 | 117 | from ansible.plugins.vars import BaseVarsPlugin
|
122 | 118 | from ansible.inventory.host import Host
|
123 | 119 | from ansible_collections.codeaffen.hieradata.plugins.module_utils.vars import combine_vars
|
| 120 | +from ansible_collections.codeaffen.hieradata.plugins.module_utils.hieradata import parse_config |
124 | 121 |
|
125 | 122 | FOUND = {}
|
126 | 123 |
|
@@ -185,29 +182,3 @@ def get_vars(self, loader, path, entities, cache=True):
|
185 | 182 | raise AnsibleParserError(to_native(e))
|
186 | 183 |
|
187 | 184 | return hieradata
|
188 |
| - |
189 |
| - |
190 |
| -def parse_config(entity, config): |
191 |
| - """Loads hieradata.yml and parse its content |
192 |
| -
|
193 |
| - :param entity: the entity for what the configuration will be parsed |
194 |
| - :type entity: str |
195 |
| - :param parse: the type of entity we want to parse the configuration, defaults to "both" |
196 |
| - :type parse: str, optional |
197 |
| - :return: list of paths which reflects the hierarchy |
198 |
| - :rtype: list |
199 |
| - """ |
200 |
| - with open(config) as fd: |
201 |
| - fd_data = yaml.load(fd, Loader=SafeLoader) |
202 |
| - |
203 |
| - hiera_vars = {} |
204 |
| - for k, v in fd_data['hiera_vars'].items(): |
205 |
| - t = Template(v) |
206 |
| - hiera_vars[k] = t.render(entity=entity) |
207 |
| - |
208 |
| - hierarchy = [] |
209 |
| - for i, entry in enumerate(fd_data['hierarchy']): |
210 |
| - t = Template(entry) |
211 |
| - hierarchy.insert(i, t.render(hiera_vars)) |
212 |
| - |
213 |
| - return hierarchy |
0 commit comments