Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
ad821dc7
Commit
ad821dc7
authored
Mar 30, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run playbook.yml
parent
219855d6
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
150 additions
and
76 deletions
+150
-76
ansible_example.py
drip-deployer/ansible_example.py
+69
-71
ansible_playbook.py
drip-deployer/ansible_playbook.py
+1
-5
id_ras
drip-deployer/id_ras
+27
-0
id_ras.pub
drip-deployer/id_ras.pub
+1
-0
playbook.yml
drip-deployer/playbook.yml
+1
-0
results_collector.py
drip-deployer/results_collector.py
+51
-0
results_collector.pyc
drip-deployer/results_collector.pyc
+0
-0
No files found.
drip-deployer/ansible_example.py
View file @
ad821dc7
...
@@ -7,93 +7,91 @@ from ansible.vars import VariableManager
...
@@ -7,93 +7,91 @@ from ansible.vars import VariableManager
from
ansible.inventory
import
Inventory
from
ansible.inventory
import
Inventory
from
ansible.playbook.play
import
Play
from
ansible.playbook.play
import
Play
from
ansible.executor.task_queue_manager
import
TaskQueueManager
from
ansible.executor.task_queue_manager
import
TaskQueueManager
from
ansible.plugins.callback
import
CallbackBase
import
ansible.executor.task_queue_manager
import
ansible.executor.task_queue_manager
import
ansible.inventory
import
ansible.inventory
import
ansible.parsing.dataloader
import
ansible.parsing.dataloader
import
ansible.playbook.play
import
ansible.playbook.play
import
ansible.plugins.callback
import
ansible.plugins.callback
import
ansible.vars
import
ansible.vars
from
ansible.executor.playbook_executor
import
PlaybookExecutor
from
ansible.plugins
import
callback_loader
import
os
import
logging
import
yaml
import
sys
from
results_collector
import
ResultsCollector
class
ResultCallback
(
CallbackBase
):
"""A sample callback plugin used for performing an action as results come in
If you want to collect all results into a single object for processing at
hosts
=
'172.17.0.2,172.17.0.3,'
the end of the execution, look into utilizing the ``json`` callback plugin
playbook_path
=
'playbook.yml'
or writing your own custom callback plugin
if
not
os
.
path
.
exists
(
playbook_path
):
"""
print
'[ERROR] The playbook does not exist'
def
v2_runner_on_ok
(
self
,
result
,
**
kwargs
):
sys
.
exit
()
"""Print a json representation of the result
This method could store the result in an instance attribute for retrieval later
user
=
'vm_user'
"""
ssh_key_file
=
'id_ras'
host
=
result
.
_host
extra_vars
=
{
'resultslocation'
:
'/tmp/res'
}
print
json
.
dumps
({
host
.
name
:
result
.
_result
})
class
Options
(
object
):
variable_manager
=
VariableManager
()
loader
=
DataLoader
()
def
__init__
(
self
,
check
=
True
):
inventory
=
Inventory
(
loader
=
loader
,
variable_manager
=
variable_manager
,
host_list
=
hosts
)
self
.
connection
=
"smart"
self
.
module_path
=
None
self
.
forks
=
None
self
.
remote_user
=
None
self
.
private_key_file
=
None
self
.
ssh_common_args
=
None
self
.
ssh_extra_args
=
None
self
.
sftp_extra_args
=
None
self
.
scp_extra_args
=
None
self
.
become
=
None
self
.
become_method
=
None
self
.
become_user
=
None
self
.
verbosity
=
None
self
.
check
=
check
super
(
Options
,
self
)
.
__init__
()
Options
=
namedtuple
(
'Options'
,
[
'listtags'
,
'listtasks'
,
'listhosts'
,
'syntax'
,
'connection'
,
'module_path'
,
'forks'
,
'remote_user'
,
'private_key_file'
,
'ssh_common_args'
,
'ssh_extra_args'
,
'sftp_extra_args'
,
'scp_extra_args'
,
'become'
,
'become_method'
,
'become_user'
,
'verbosity'
,
'check'
])
options
=
Options
(
check
=
False
)
options
=
Options
(
listtags
=
False
,
listtasks
=
False
,
listhosts
=
False
,
syntax
=
False
,
connection
=
'smart'
,
module_path
=
None
,
forks
=
None
,
remote_user
=
user
,
private_key_file
=
ssh_key_file
,
ssh_common_args
=
None
,
ssh_extra_args
=
None
,
sftp_extra_args
=
None
,
scp_extra_args
=
None
,
become
=
True
,
become_method
=
'sudo'
,
become_user
=
'root'
,
verbosity
=
None
,
check
=
False
)
# initialize needed objects
variable_manager
=
ansible
.
vars
.
VariableManager
()
loader
=
DataLoader
()
# Instantiate our ResultCallback for handling results as they come in
variable_manager
.
extra_vars
=
extra_vars
results_callback
=
ResultCallback
()
passwords
=
{}
# create inventory and pass to var manager
inventory
=
Inventory
(
loader
=
loader
,
variable_manager
=
variable_manager
,
host_list
=
'172.17.0.4,172.17.0.5'
)
variable_manager
.
set_inventory
(
inventory
)
# create play with tasks
play_source
=
dict
(
name
=
"Ansible Play"
,
hosts
=
'all'
,
gather_facts
=
'no'
,
tasks
=
[
dict
(
action
=
dict
(
module
=
'shell'
,
args
=
'ls'
),
register
=
'shell_out'
)
#,dict(action=dict(module='debug', args=dict(msg='{{shell_out.stdout}}')))
]
)
play
=
Play
()
.
load
(
play_source
,
variable_manager
=
variable_manager
,
loader
=
loader
)
# actually run it
pbex
=
PlaybookExecutor
(
playbooks
=
[
playbook_path
],
tqm
=
None
try
:
tqm
=
TaskQueueManager
(
inventory
=
inventory
,
inventory
=
inventory
,
variable_manager
=
variable_manager
,
variable_manager
=
variable_manager
,
loader
=
loader
,
loader
=
loader
,
options
=
options
,
options
=
options
,
passwords
=
None
,
passwords
=
passwords
,
#stdout_callback='json',
stdout_callback
=
results_callback
,
# Use our custom callback instead of the ``default`` callback plugin
#stdout_callback='default',
)
)
result
=
tqm
.
run
(
play
)
results_callback
=
ResultsCollector
()
finally
:
pbex
.
_tqm
.
_stdout_callback
=
results_callback
if
tqm
is
not
None
:
results
=
pbex
.
run
()
tqm
.
cleanup
()
\ No newline at end of file
ok
=
results_callback
.
host_ok
count
=
0
;
for
res
in
ok
:
re
=
json
.
dumps
(
res
[
'result'
]
.
_result
)
++
count
target
=
open
(
"ok"
+
str
(
count
)
+
".json"
,
'w'
)
target
.
write
(
re
)
target
.
close
()
print
re
count
=
0
;
unreachable
=
results_callback
.
host_unreachable
for
res
in
unreachable
:
re
=
json
.
dumps
(
res
[
'result'
]
.
_result
)
++
count
target
=
open
(
"unreachable"
+
str
(
count
)
+
".json"
,
'w'
)
target
.
write
(
re
)
target
.
close
()
print
re
count
=
0
;
host_failed
=
results_callback
.
host_failed
for
res
in
host_failed
:
re
=
json
.
dumps
(
res
[
'result'
]
.
_result
)
++
count
target
=
open
(
"host_failed"
+
str
(
count
)
+
".json"
,
'w'
)
target
.
write
(
re
)
target
.
close
()
print
re
\ No newline at end of file
drip-deployer/ansible_playbook.py
View file @
ad821dc7
...
@@ -20,7 +20,7 @@ __author__ = 'S. Koulouzis'
...
@@ -20,7 +20,7 @@ __author__ = 'S. Koulouzis'
import
paramiko
,
os
import
paramiko
,
os
import
threading
import
threading
import
ansible.runner
import
ansible.runner
from
ansible.playbook
import
PlayBook
from
results_collector
import
ResultsCollector
def
install_prerequisites
(
vm
):
def
install_prerequisites
(
vm
):
try
:
try
:
...
@@ -50,8 +50,4 @@ def run(vm_list,playbook):
...
@@ -50,8 +50,4 @@ def run(vm_list,playbook):
user
=
vm
.
user
user
=
vm
.
user
if
"ERROR"
in
ret
:
return
ret
if
"ERROR"
in
ret
:
return
ret
# construct the ansible runner and execute on all hosts
results
=
ansible
.
runner
.
Runner
(
pattern
=
'*'
,
forks
=
10
,
module_name
=
'command'
,
module_args
=
'/usr/bin/uptime'
,)
.
run
()
return
"SUCCESS"
return
"SUCCESS"
\ No newline at end of file
drip-deployer/id_ras
0 → 100644
View file @
ad821dc7
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAvwasjBZG8lAvO0+FnNWuAtQjyrWJ8X3sZijjrVLWLqfgrbx3
837U78DDuFXspHF4/rUN5yZ4ggt/3HSrOzTVhLy0K7bQAUeZG0J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dKYcVhvRLUP4lGVljkwEy5wugQV92kQ
z104GSK/YbFBQTzpmY/ugQKBgCMIalg6nW8wu6Z0ivo1DJ4tZEkLc4CZEdWZAbV5
dALbRfKctgaDVDs0+WF1mATP/r89EmXEVu8YDVj6yU+gQK3zSwO+OVP7iBFODwJN
4i0DcbROgSoMyLmmmG5oVTe6HRTrRnNE7kOzZL5KJsbrowIoErJO7+749f06DOam
ka+RAoGBAJ5+awU/gJusZW1K+dAVIYtY9lwB/HFlTnsPIpgUPpdywilESlowD7dH
JnthsSbFmzl/KorI8megzelC/HDotig78GViL45s/LxnvuSvVmxBK2nb44KmHTV4
ypE44UC+s5BEe/aTUtke5mmVY5lLR2SoCeUCKA2llKhrskvt+/cZ
-----END RSA PRIVATE KEY-----
drip-deployer/id_ras.pub
0 → 100755
View file @
ad821dc7
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/BqyMFkbyUC87T4Wc1a4C1CPKtYnxfexmKOOtUtYup+CtvHfzftTvwMO4VeykcXj+tQ3nJniCC3/cdKs7NNWEvLQrttABR5kbQlD1rjCRjsLAZ+KuCyRBXIBM41mzl+oFrnjjeoVI4uWWawyOi56zt2XX/10aqxvU2TGd4LYdKno4Nve6uL3+zz5bSvp1pzeQilEQJYgTMZka06YB9ZnDCSRJch2MnaBP564NMAJrVg3lOHIKskfNhG4MQO9OaMppv4ryG/3LOTZ1a8pgxi7RZk4+cN/Z7rGVXJuXa5N4NWVdMiW274OK+jx+vPKEBl0wt7z2Ro8BXaAjgZfsibjR alogo@hermes
drip-deployer/playbook.yml
View file @
ad821dc7
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
-
expect
-
expect
-
git
-
git
-
python-pexpect
-
python-pexpect
-
php-zip
become
:
true
become
:
true
-
name
:
Phoronix-test-suite accept User Agreement
-
name
:
Phoronix-test-suite accept User Agreement
...
...
drip-deployer/results_collector.py
0 → 100644
View file @
ad821dc7
#!/usr/bin/env python
# Copyright 2017 S. Koulouzis
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
ansible.plugins.callback
import
CallbackBase
__author__
=
'S. Koulouzis'
class
ResultsCollector
(
CallbackBase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ResultsCollector
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
host_ok
=
[]
self
.
host_unreachable
=
[]
self
.
host_failed
=
[]
def
v2_runner_on_unreachable
(
self
,
result
,
ignore_errors
=
False
):
name
=
result
.
_host
.
get_name
()
task
=
result
.
_task
.
get_name
()
#self.host_unreachable[result._host.get_name()] = result
self
.
host_unreachable
.
append
(
dict
(
ip
=
name
,
task
=
task
,
result
=
result
))
def
v2_runner_on_ok
(
self
,
result
,
*
args
,
**
kwargs
):
name
=
result
.
_host
.
get_name
()
task
=
result
.
_task
.
get_name
()
if
task
==
"setup"
:
pass
elif
"Info"
in
task
:
self
.
host_ok
.
append
(
dict
(
ip
=
name
,
task
=
task
,
result
=
result
))
else
:
self
.
host_ok
.
append
(
dict
(
ip
=
name
,
task
=
task
,
result
=
result
))
def
v2_runner_on_failed
(
self
,
result
,
*
args
,
**
kwargs
):
name
=
result
.
_host
.
get_name
()
task
=
result
.
_task
.
get_name
()
self
.
host_failed
.
append
(
dict
(
ip
=
name
,
task
=
task
,
result
=
result
))
\ No newline at end of file
drip-deployer/results_collector.pyc
0 → 100644
View file @
ad821dc7
File added
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