mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
|
else:
|
||||||
print >>sys.stderr, "err: [%s] => %s" % (host, err)
|
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
|
print "skipping: [%s]" % host
|
||||||
|
|
||||||
def on_no_hosts(self):
|
def on_no_hosts(self):
|
||||||
|
|
|
@ -31,6 +31,7 @@ import base64
|
||||||
import getpass
|
import getpass
|
||||||
import codecs
|
import codecs
|
||||||
import collections
|
import collections
|
||||||
|
import re
|
||||||
|
|
||||||
import ansible.constants as C
|
import ansible.constants as C
|
||||||
import ansible.inventory
|
import ansible.inventory
|
||||||
|
@ -555,7 +556,7 @@ class Runner(object):
|
||||||
conditional = utils.template(self.conditional, inject)
|
conditional = utils.template(self.conditional, inject)
|
||||||
if not eval(conditional):
|
if not eval(conditional):
|
||||||
result = utils.jsonify(dict(skipped=True))
|
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)
|
return ReturnData(host=host, result=result)
|
||||||
|
|
||||||
conn = None
|
conn = None
|
||||||
|
|
Loading…
Reference in a new issue