From 8bc2d3be9c41348123af9ad391dd649df5664568 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 4 Feb 2016 09:58:50 -0600 Subject: [PATCH] Add new 'unsafe' YAML constructor --- lib/ansible/parsing/yaml/constructor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ansible/parsing/yaml/constructor.py b/lib/ansible/parsing/yaml/constructor.py index bac0d3f2a5..164d23b497 100644 --- a/lib/ansible/parsing/yaml/constructor.py +++ b/lib/ansible/parsing/yaml/constructor.py @@ -22,6 +22,7 @@ __metaclass__ = type from yaml.constructor import Constructor, ConstructorError from yaml.nodes import MappingNode from ansible.parsing.yaml.objects import AnsibleMapping, AnsibleSequence, AnsibleUnicode +from ansible.vars.unsafe_proxy import wrap_var try: from __main__ import display @@ -72,7 +73,7 @@ class AnsibleConstructor(Constructor): return mapping - def construct_yaml_str(self, node): + def construct_yaml_str(self, node, unsafe=False): # Override the default string handling function # to always return unicode objects value = self.construct_scalar(node) @@ -80,6 +81,9 @@ class AnsibleConstructor(Constructor): ret.ansible_pos = self._node_position_info(node) + if unsafe: + ret = wrap_var(ret) + return ret def construct_yaml_seq(self, node): @@ -88,6 +92,9 @@ class AnsibleConstructor(Constructor): data.extend(self.construct_sequence(node)) data.ansible_pos = self._node_position_info(node) + def construct_yaml_unsafe(self, node): + return self.construct_yaml_str(node, unsafe=True) + def _node_position_info(self, node): # the line number where the previous token has ended (plus empty lines) # Add one so that the first line is line 1 rather than line 0 @@ -121,3 +128,7 @@ AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor( u'tag:yaml.org,2002:seq', AnsibleConstructor.construct_yaml_seq) + +AnsibleConstructor.add_constructor( + u'!unsafe', + AnsibleConstructor.construct_yaml_unsafe)