From 4b9b9a8a5b21abaff0b6c217807579fe5930afc1 Mon Sep 17 00:00:00 2001 From: Timothy Appnel Date: Mon, 23 Jul 2012 19:36:26 -0400 Subject: [PATCH] Importing re in runner for doing conditional tasks using pattern matching i.e. re.search(). Also conditionally outputting item when skipping. --- lib/ansible/callbacks.py | 5 ++++- lib/ansible/runner/__init__.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index 7f8a1692ed..fc8d29162f 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -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): diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 30583a8750..073d273f33 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -31,6 +31,7 @@ import base64 import getpass import codecs import collections +import re import ansible.constants as C import ansible.inventory @@ -548,7 +549,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