1414
1515from ansible .plugins .action import ActionBase
1616
17+ # TODO(dougszu): From Ansible 12 onwards we must explicitly trust templates.
18+ # Since this feature is not supported in previous releases, we define a
19+ # noop method here for backwards compatibility. This can be removed in the
20+ # G cycle.
21+ try :
22+ from ansible .template import trust_as_template
23+ except ImportError :
24+ def trust_as_template (template ):
25+ return template
26+
1727
1828class ConfigError (Exception ):
1929 pass
@@ -28,6 +38,11 @@ class ActionModule(ActionBase):
2838
2939 TRANSFERS_FILES = False
3040
41+ def trusted_template (self , input ):
42+ # Mark all input as trusted.
43+ trusted_input = trust_as_template (input )
44+ return self ._templar .template (trusted_input )
45+
3146 def run (self , tmp = None , task_vars = None ):
3247 if task_vars is None :
3348 task_vars = dict ()
@@ -97,11 +112,11 @@ def _run(self, interfaces, external_networks):
97112 def _get_interface_fact (self , net_name , required , description ):
98113 # Check whether the network is mapped to this host.
99114 condition = "{{ '%s' in network_interfaces }}" % net_name
100- condition = self ._templar . template (condition )
115+ condition = self .trusted_template (condition )
101116 if condition :
102117 # Get the network interface for this network.
103118 iface = ("{{ '%s' | net_interface }}" % net_name )
104- iface = self ._templar . template (iface )
119+ iface = self .trusted_template (iface )
105120 if required and not iface :
106121 msg = ("Required network '%s' (%s) does not have an interface "
107122 "configured for this host" % (net_name , description ))
@@ -114,20 +129,20 @@ def _get_interface_fact(self, net_name, required, description):
114129
115130 def _get_external_interface (self , net_name , required ):
116131 condition = "{{ '%s' in network_interfaces }}" % net_name
117- condition = self ._templar . template (condition )
132+ condition = self .trusted_template (condition )
118133 if condition :
119- iface = self ._templar . template ("{{ '%s' | net_interface }}" %
120- net_name )
134+ iface = self .trusted_template ("{{ '%s' | net_interface }}" %
135+ net_name )
121136 if iface :
122137 # When these networks are VLANs, we need to use the
123138 # underlying tagged bridge interface rather than the
124139 # untagged interface. We therefore strip the .<vlan> suffix
125140 # of the interface name. We use a union here as a single
126141 # tagged interface may be shared between these networks.
127- vlan = self ._templar . template ("{{ '%s' | net_vlan }}" %
128- net_name )
129- parent = self ._templar . template ("{{ '%s' | net_parent }}" %
130- net_name )
142+ vlan = self .trusted_template ("{{ '%s' | net_vlan }}" %
143+ net_name )
144+ parent = self .trusted_template ("{{ '%s' | net_parent }}" %
145+ net_name )
131146 if vlan and parent :
132147 iface = parent
133148 elif vlan and iface .endswith (".%s" % vlan ):
@@ -146,15 +161,15 @@ def _get_external_interface_facts(self, external_interfaces):
146161 neutron_external_interfaces = []
147162 neutron_physical_networks = []
148163 missing_physical_networks = []
149- bridge_suffix = self ._templar . template (
164+ bridge_suffix = self .trusted_template (
150165 "{{ network_bridge_suffix_ovs }}" )
151- patch_prefix = self ._templar . template ("{{ network_patch_prefix }}" )
152- patch_suffix = self ._templar . template ("{{ network_patch_suffix_ovs }}" )
166+ patch_prefix = self .trusted_template ("{{ network_patch_prefix }}" )
167+ patch_suffix = self .trusted_template ("{{ network_patch_suffix_ovs }}" )
153168 for interface , iface_networks in external_interfaces .items ():
154169 is_bridge = ("{{ '%s' in (network_interfaces |"
155170 "net_select_bridges |"
156171 "map('net_interface')) }}" % interface )
157- is_bridge = self ._templar . template (is_bridge )
172+ is_bridge = self .trusted_template (is_bridge )
158173 neutron_bridge_names .append (interface + bridge_suffix )
159174 # For a bridge, use a veth pair connected to the bridge. Otherwise
160175 # use the interface directly.
@@ -171,7 +186,7 @@ def _get_external_interface_facts(self, external_interfaces):
171186 # attribute set, and if so, whether they are consistent.
172187 iface_physical_networks = []
173188 for iface_network in iface_networks :
174- physical_network = self ._templar . template (
189+ physical_network = self .trusted_template (
175190 "{{ '%s' | net_physical_network }}" % iface_network )
176191 if (physical_network and
177192 physical_network not in iface_physical_networks ):
0 commit comments