mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Enable usage of when_set within new eval system.
This commit is contained in:
parent
a83e10d77d
commit
0113951580
2 changed files with 11 additions and 8 deletions
|
@ -15,6 +15,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ansible.utils import safe_eval
|
||||
|
||||
def flatten(terms):
|
||||
ret = []
|
||||
|
@ -40,6 +41,10 @@ class LookupModule(object):
|
|||
pass
|
||||
|
||||
def run(self, terms, **kwargs):
|
||||
if '{' or '[' in terms:
|
||||
# Jinja2-ified list needs to be converted back to a real type
|
||||
# TODO: something a bit less heavy than eval
|
||||
terms = safe_eval(terms)
|
||||
if not isinstance(terms, list):
|
||||
raise errors.AnsibleError("a list is required for with_nested")
|
||||
my_list = terms[:]
|
||||
|
|
|
@ -154,11 +154,6 @@ def check_conditional(conditional):
|
|||
if not isinstance(conditional, basestring):
|
||||
return conditional
|
||||
|
||||
def is_set(var):
|
||||
return not var.startswith("$") and not '{{' in var
|
||||
|
||||
def is_unset(var):
|
||||
return var.startswith("$") or '{{' in var
|
||||
|
||||
try:
|
||||
conditional = conditional.replace("\n", "\\n")
|
||||
|
@ -694,13 +689,16 @@ def safe_eval(str):
|
|||
'''
|
||||
# FIXME: is there a more native way to do this?
|
||||
|
||||
# do not allow method calls
|
||||
def is_set(var):
|
||||
return not var.startswith("$") and not '{{' in var
|
||||
def is_unset(var):
|
||||
return var.startswith("$") or '{{' in var
|
||||
|
||||
# do not allow method calls to modules
|
||||
if re.search(r'\w\.\w+\(', str):
|
||||
print "C1"
|
||||
return str
|
||||
# do not allow imports
|
||||
if re.search(r'import \w+', str):
|
||||
print "C2"
|
||||
return str
|
||||
return eval(str)
|
||||
|
||||
|
|
Loading…
Reference in a new issue