Merge pull request #662 from tima/regex-cond-tasks
Importing re in runner for doing conditional tasks using pattern matching i.e. re.search(). Also conditionally outputting item when skipping.
This commit is contained in:
commit
183330a9fa
2 changed files with 6 additions and 2 deletions
|
@ -291,8 +291,11 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
|
|||
else:
|
||||
print >>sys.stderr, "err: [%s] => %s" % (host, err)
|
||||
|
||||
def on_skipped(self, host):
|
||||
def on_skipped(self, host, item=None):
|
||||
|
||||
if item:
|
||||
print "skipping: [%s] => (item=%s)" % (host, item)
|
||||
else:
|
||||
print "skipping: [%s]" % host
|
||||
|
||||
def on_no_hosts(self):
|
||||
|
|
|
@ -31,6 +31,7 @@ import base64
|
|||
import getpass
|
||||
import codecs
|
||||
import collections
|
||||
import re
|
||||
|
||||
import ansible.constants as C
|
||||
import ansible.inventory
|
||||
|
@ -555,7 +556,7 @@ class Runner(object):
|
|||
conditional = utils.template(self.conditional, inject)
|
||||
if not eval(conditional):
|
||||
result = utils.jsonify(dict(skipped=True))
|
||||
self.callbacks.on_skipped(host)
|
||||
self.callbacks.on_skipped(host, inject.get('item',None))
|
||||
return ReturnData(host=host, result=result)
|
||||
|
||||
conn = None
|
||||
|
|
Loading…
Reference in a new issue