mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 06:30:19 -07:00
Clean string data run through the template engine
Also strip UnsafeProxy off of low level srings and objects to ensure they don't cause issues later down the road Fixes #12513
This commit is contained in:
parent
ae9b34b1d9
commit
cdc6c5208e
3 changed files with 84 additions and 29 deletions
|
@ -37,7 +37,7 @@ from ansible.playbook.included_file import IncludedFile
|
|||
from ansible.playbook.role import hash_params
|
||||
from ansible.plugins import action_loader, connection_loader, filter_loader, lookup_loader, module_loader
|
||||
from ansible.template import Templar
|
||||
from ansible.vars.unsafe_proxy import UnsafeProxy
|
||||
from ansible.vars.unsafe_proxy import wrap_var
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
|
@ -244,31 +244,8 @@ class StrategyBase:
|
|||
# the variable goes in the fact_cache
|
||||
host = result[1]
|
||||
var_name = result[2]
|
||||
var_value = result[3]
|
||||
var_value = wrap_var(result[3])
|
||||
|
||||
def _wrap_var(v):
|
||||
if isinstance(v, dict):
|
||||
v = _wrap_dict(v)
|
||||
elif isinstance(v, list):
|
||||
v = _wrap_list(v)
|
||||
else:
|
||||
if v is not None and not isinstance(v, UnsafeProxy):
|
||||
v = UnsafeProxy(v)
|
||||
return v
|
||||
|
||||
def _wrap_dict(v):
|
||||
for k in v.keys():
|
||||
if v[k] is not None and not isinstance(v[k], UnsafeProxy):
|
||||
v[k] = _wrap_var(v[k])
|
||||
return v
|
||||
|
||||
def _wrap_list(v):
|
||||
for idx, item in enumerate(v):
|
||||
if item is not None and not isinstance(item, UnsafeProxy):
|
||||
v[idx] = _wrap_var(item)
|
||||
return v
|
||||
|
||||
var_value = _wrap_var(var_value)
|
||||
self._variable_manager.set_nonpersistent_facts(host, {var_name: var_value})
|
||||
|
||||
elif result[0] in ('set_host_var', 'set_host_facts'):
|
||||
|
@ -291,7 +268,8 @@ class StrategyBase:
|
|||
|
||||
if result[0] == 'set_host_var':
|
||||
var_name = result[4]
|
||||
var_value = result[5]
|
||||
var_value = wrap_var(result[5])
|
||||
|
||||
self._variable_manager.set_host_variable(target_host, var_name, var_value)
|
||||
elif result[0] == 'set_host_facts':
|
||||
facts = result[4]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue