Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
fd3d1098
Commit
fd3d1098
authored
Jul 14, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sivel-wait-for-port-search-regex' into devel
parents
4be891f6
eb80bd1a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
7 deletions
+28
-7
library/utilities/wait_for
+28
-7
No files found.
library/utilities/wait_for
View file @
fd3d1098
...
...
@@ -76,9 +76,9 @@ options:
version_added: "1.4"
required: false
description:
-
with the path option can be used match a string in the file that must match before continuing.
Defaults to a multiline regex.
notes: []
-
Can be used to match a string in either a file or a socket connection.
Defaults to a multiline regex.
notes:
- The ability to use search_regex with a port connection was added in 1.7.
requirements: []
author: Jeroen Hoekx, John Jarvis, Andrii Radyk
'''
...
...
@@ -100,6 +100,9 @@ EXAMPLES = '''
# wait until the process is finished and pid was destroyed
- wait_for: path=/proc/3466/status state=absent
# Wait 300 seconds for port 22 to become open and contain "OpenSSH", don't start checking for 10 seconds
- local_action: wait_for port=22 host="{{ inventory_hostname }}" search_regex=OpenSSH delay=10
'''
def
main
():
...
...
@@ -205,16 +208,34 @@ def main():
s
.
settimeout
(
connect_timeout
)
try
:
s
.
connect
(
(
host
,
port
)
)
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
close
()
break
if
search_regex
:
data
=
''
matched
=
False
while
1
:
data
+=
s
.
recv
(
1024
)
if
not
data
:
break
elif
re
.
search
(
search_regex
,
data
,
re
.
MULTILINE
):
matched
=
True
break
if
matched
:
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
close
()
break
else
:
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
close
()
break
except
:
time
.
sleep
(
1
)
pass
else
:
elapsed
=
datetime
.
datetime
.
now
()
-
start
if
port
:
module
.
fail_json
(
msg
=
"Timeout when waiting for
%
s:
%
s"
%
(
host
,
port
),
elapsed
=
elapsed
.
seconds
)
if
search_regex
:
module
.
fail_json
(
msg
=
"Timeout when waiting for search string
%
s in
%
s:
%
s"
%
(
search_regex
,
host
,
port
),
elapsed
=
elapsed
.
seconds
)
else
:
module
.
fail_json
(
msg
=
"Timeout when waiting for
%
s:
%
s"
%
(
host
,
port
),
elapsed
=
elapsed
.
seconds
)
elif
path
:
if
search_regex
:
module
.
fail_json
(
msg
=
"Timeout when waiting for search string
%
s in
%
s"
%
(
search_regex
,
path
),
elapsed
=
elapsed
.
seconds
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment