Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Douglas
slapos.package
Commits
f0da81b1
Commit
f0da81b1
authored
Jul 31, 2015
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add task to ping one or multiple hosts
parent
0ee609e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletion
+45
-1
playbook/roles/vm-bootstrap/files/ping
playbook/roles/vm-bootstrap/files/ping
+35
-0
playbook/roles/vm-bootstrap/tasks/hostname.yml
playbook/roles/vm-bootstrap/tasks/hostname.yml
+10
-1
No files found.
playbook/roles/vm-bootstrap/files/ping
0 → 100644
View file @
f0da81b1
#!/usr/bin/python
import
os
import
sys
from
subprocess
import
Popen
,
PIPE
def
check_ping
(
host_list
):
for
host
in
host_list
:
process
=
Popen
(
"ping -c 1 %s"
%
host
,
shell
=
True
,
stdout
=
PIPE
)
result
=
process
.
communicate
()[
0
]
if
process
.
returncode
==
0
:
continue
raise
Exception
(
'PING fail: host at %s didn
\
'
t send response.
\
n
%s'
%
(
host
,
result
))
def
ping_cluster
(
hpath
):
if
os
.
path
.
exists
(
hpath
):
for
content
in
open
(
hpath
,
'r'
).
readlines
():
if
content
:
items
=
content
.
strip
().
split
(
' '
)
check_ping
(
items
)
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
<
3
:
print
"Use: %s TYPE [HOST LIST] OR [HOST-FILE]"
%
sys
.
argv
[
0
]
print
"ex: %s host google.com slapos.org; %s cluster /tmp/hosts"
%
(
sys
.
argv
[
0
],
sys
.
argv
[
0
])
exit
(
1
)
if
sys
.
argv
[
1
]
==
'host'
:
check_ping
(
sys
.
argv
[
2
:])
elif
sys
.
argv
[
1
]
==
'cluster'
:
ping_cluster
(
sys
.
argv
[
2
])
playbook/roles/vm-bootstrap/tasks/hostname.yml
View file @
f0da81b1
...
@@ -46,7 +46,7 @@
...
@@ -46,7 +46,7 @@
-
name
:
stat /tmp/hosts
-
name
:
stat /tmp/hosts
stat
:
path=/tmp/hosts
stat
:
path=/tmp/hosts
register
:
host
name
_file
register
:
host
s
_file
-
name
:
Format hosts
-
name
:
Format hosts
script
:
format_hosts /tmp/hosts tl.teralab-datascience.fr
script
:
format_hosts /tmp/hosts tl.teralab-datascience.fr
...
@@ -57,3 +57,12 @@
...
@@ -57,3 +57,12 @@
-
name
:
adding entry from workspace
-
name
:
adding entry from workspace
lineinfile
:
dest=/etc/resolv.conf line="nameserver 10.200.218.1"
lineinfile
:
dest=/etc/resolv.conf line="nameserver 10.200.218.1"
-
name
:
ping current host
script
:
ping host {{ lookup('file', '/etc/opt/ipv4') }} {{ lookup('file', '/etc/opt/hostname') }}
when
:
hostname_file.stat.exists == True
-
name
:
ping cluster hosts
script
:
ping cluster /tmp/hosts
when
:
hosts_file.stat.exists == True
ignore_errors
:
True
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