Commit 767a13cc by John Jarvis

search_string changed to search_regex

parent 022c37ba
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
wait_for: > wait_for: >
path=/var/log/cloud-init.log path=/var/log/cloud-init.log
timeout=15 timeout=15
search_string=final-message search_regex="final-message"
roles: roles:
# rerun common to set the hostname # rerun common to set the hostname
- common - common
......
...@@ -75,7 +75,7 @@ EXAMPLES = ''' ...@@ -75,7 +75,7 @@ EXAMPLES = '''
- wait_for: path=/tmp/foo state=present - wait_for: path=/tmp/foo state=present
# wait until the string "completed" is in the file /tmp/foo before continuing # wait until the string "completed" is in the file /tmp/foo before continuing
- wait_for: path=/tmp/foo search_string=completed state=present - wait_for: path=/tmp/foo search_regex=completed state=present
''' '''
...@@ -89,7 +89,7 @@ def main(): ...@@ -89,7 +89,7 @@ def main():
delay=dict(default=0), delay=dict(default=0),
port=dict(default=None), port=dict(default=None),
path=dict(default=None), path=dict(default=None),
search_string=dict(default=None), search_regex=dict(default=None),
state=dict(default='started', choices=['started', 'stopped', 'present']), state=dict(default='started', choices=['started', 'stopped', 'present']),
), ),
) )
...@@ -106,7 +106,7 @@ def main(): ...@@ -106,7 +106,7 @@ def main():
port = None port = None
state = params['state'] state = params['state']
path = params['path'] path = params['path']
search_string = params['search_string'] search_regex = params['search_regex']
if port and path: if port and path:
module.fail_json(msg="port and path parameter can not both be passed to wait_for") module.fail_json(msg="port and path parameter can not both be passed to wait_for")
...@@ -143,8 +143,8 @@ def main(): ...@@ -143,8 +143,8 @@ def main():
if path: if path:
try: try:
with open(path) as f: with open(path) as f:
if search_string: if search_regex:
if search_string in f.read(): if re.search(search_regex, f.read(), re.MULTILINE):
break break
else: else:
time.sleep(1) time.sleep(1)
...@@ -169,14 +169,14 @@ def main(): ...@@ -169,14 +169,14 @@ def main():
if port: if port:
module.fail_json(msg="Timeout when waiting for %s:%s" % (host, port), elapsed=elapsed.seconds) module.fail_json(msg="Timeout when waiting for %s:%s" % (host, port), elapsed=elapsed.seconds)
elif path: elif path:
if search_string: if search_regex:
module.fail_json(msg="Timeout when waiting for search string %s in %s" % (search_string, path), elapsed=elapsed.seconds) module.fail_json(msg="Timeout when waiting for search string %s in %s" % (search_regex, path), elapsed=elapsed.seconds)
else: else:
module.fail_json(msg="Timeout when waiting for file %s" % (path), elapsed=elapsed.seconds) module.fail_json(msg="Timeout when waiting for file %s" % (path), elapsed=elapsed.seconds)
elapsed = datetime.datetime.now() - start elapsed = datetime.datetime.now() - start
module.exit_json(state=state, port=port, search_string=search_string, path=path, elapsed=elapsed.seconds) module.exit_json(state=state, port=port, search_regex=search_regex, path=path, elapsed=elapsed.seconds)
# this is magic, see lib/ansible/module_common.py # this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>> #<<INCLUDE_ANSIBLE_MODULE_COMMON>>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment