added ability to control sleep between attempts
the default was 1s but it makes sense to make this configurable
This commit is contained in:
parent
97b23c0fb7
commit
9e931f89fb
1 changed files with 18 additions and 8 deletions
|
@ -78,28 +78,39 @@ options:
|
||||||
description:
|
description:
|
||||||
- port number to poll
|
- port number to poll
|
||||||
required: false
|
required: false
|
||||||
|
default: null
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- either C(present), C(started), or C(stopped), C(absent), or C(drained)
|
- either C(present), C(started), or C(stopped), C(absent), or C(drained)
|
||||||
- When checking a port C(started) will ensure the port is open, C(stopped) will check that it is closed, C(drained) will check for active connections
|
- When checking a port C(started) will ensure the port is open, C(stopped) will check that it is closed, C(drained) will check for active connections
|
||||||
- When checking for a file or a search string C(present) or C(started) will ensure that the file or string is present before continuing, C(absent) will check that file is absent or removed
|
- When checking for a file or a search string C(present) or C(started) will ensure that the file or string is present before continuing, C(absent) will check that file is absent or removed
|
||||||
choices: [ "present", "started", "stopped", "absent", "drained" ]
|
choices: [ "present", "started", "stopped", "absent", "drained" ]
|
||||||
|
required: False
|
||||||
default: "started"
|
default: "started"
|
||||||
path:
|
path:
|
||||||
version_added: "1.4"
|
version_added: "1.4"
|
||||||
required: false
|
required: false
|
||||||
|
default: null
|
||||||
description:
|
description:
|
||||||
- path to a file on the filesytem that must exist before continuing
|
- path to a file on the filesytem that must exist before continuing
|
||||||
search_regex:
|
search_regex:
|
||||||
version_added: "1.4"
|
version_added: "1.4"
|
||||||
required: false
|
required: false
|
||||||
|
default: null
|
||||||
description:
|
description:
|
||||||
- Can be used to match a string in either a file or a socket connection. Defaults to a multiline regex.
|
- Can be used to match a string in either a file or a socket connection. Defaults to a multiline regex.
|
||||||
exclude_hosts:
|
exclude_hosts:
|
||||||
version_added: "1.8"
|
version_added: "1.8"
|
||||||
required: false
|
required: false
|
||||||
|
default: null
|
||||||
description:
|
description:
|
||||||
- list of hosts or IPs to ignore when looking for active TCP connections for C(drained) state
|
- list of hosts or IPs to ignore when looking for active TCP connections for C(drained) state
|
||||||
|
sleep:
|
||||||
|
version_added: "2.1"
|
||||||
|
required: false
|
||||||
|
default: 1
|
||||||
|
description:
|
||||||
|
- Number of seconds to sleep between checks, before 2.1 this was hardcoded to 1 second.
|
||||||
notes:
|
notes:
|
||||||
- The ability to use search_regex with a port connection was added in 1.7.
|
- The ability to use search_regex with a port connection was added in 1.7.
|
||||||
requirements: []
|
requirements: []
|
||||||
|
@ -362,7 +373,8 @@ def main():
|
||||||
path=dict(default=None, type='path'),
|
path=dict(default=None, type='path'),
|
||||||
search_regex=dict(default=None),
|
search_regex=dict(default=None),
|
||||||
state=dict(default='started', choices=['started', 'stopped', 'present', 'absent', 'drained']),
|
state=dict(default='started', choices=['started', 'stopped', 'present', 'absent', 'drained']),
|
||||||
exclude_hosts=dict(default=None, type='list')
|
exclude_hosts=dict(default=None, type='list'),
|
||||||
|
sleep=dict(default=1, type='int')
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -407,8 +419,6 @@ def main():
|
||||||
try:
|
try:
|
||||||
f = open(path)
|
f = open(path)
|
||||||
f.close()
|
f.close()
|
||||||
time.sleep(1)
|
|
||||||
pass
|
|
||||||
except IOError:
|
except IOError:
|
||||||
break
|
break
|
||||||
elif port:
|
elif port:
|
||||||
|
@ -416,11 +426,10 @@ def main():
|
||||||
s = _create_connection(host, port, connect_timeout)
|
s = _create_connection(host, port, connect_timeout)
|
||||||
s.shutdown(socket.SHUT_RDWR)
|
s.shutdown(socket.SHUT_RDWR)
|
||||||
s.close()
|
s.close()
|
||||||
time.sleep(1)
|
|
||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
else:
|
# Conditions not yet met, wait and try again
|
||||||
time.sleep(1)
|
time.sleep(params['sleep'])
|
||||||
else:
|
else:
|
||||||
elapsed = datetime.datetime.now() - start
|
elapsed = datetime.datetime.now() - start
|
||||||
if port:
|
if port:
|
||||||
|
@ -498,7 +507,7 @@ def main():
|
||||||
break
|
break
|
||||||
|
|
||||||
# Conditions not yet met, wait and try again
|
# Conditions not yet met, wait and try again
|
||||||
time.sleep(1)
|
time.sleep(params['sleep'])
|
||||||
|
|
||||||
else: # while-else
|
else: # while-else
|
||||||
# Timeout expired
|
# Timeout expired
|
||||||
|
@ -524,7 +533,8 @@ def main():
|
||||||
break
|
break
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
time.sleep(1)
|
# Conditions not yet met, wait and try again
|
||||||
|
time.sleep(params['sleep'])
|
||||||
else:
|
else:
|
||||||
elapsed = datetime.datetime.now() - start
|
elapsed = datetime.datetime.now() - start
|
||||||
module.fail_json(msg="Timeout when waiting for %s:%s to drain" % (host, port), elapsed=elapsed.seconds)
|
module.fail_json(msg="Timeout when waiting for %s:%s to drain" % (host, port), elapsed=elapsed.seconds)
|
||||||
|
|
Loading…
Reference in a new issue