From fd732f8d3b2546ed15e6e7f1df7dcd2353397a16 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Thu, 22 Nov 2012 23:10:11 +0100 Subject: [PATCH] Add when_boolean Fixes #1567. --- lib/ansible/playbook/task.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index fb74d6032d..3e3393e95c 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -227,6 +227,14 @@ class Task(object): else: tcopy[i] = t return " ".join(tcopy) + + # when_boolean + elif tokens[0] in [ 'bool', 'boolean' ]: + tcopy = tokens[1:] + for (i, t) in enumerate(tcopy): + if t.find("$") != -1: + tcopy[i] = "(is_set('''%s''') and '''%s'''.lower() not in ('false', 'none', '0', ''))" % (t, t) + return " ".join(tcopy) else: raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)