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
219855d6
Commit
219855d6
authored
Mar 28, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ansible example
parent
504e1228
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
6 deletions
+170
-6
ansible_example.py
drip-deployer/ansible_example.py
+99
-0
ansible_playbook.py
drip-deployer/ansible_playbook.py
+8
-5
playbook.yml
drip-deployer/playbook.yml
+63
-1
No files found.
drip-deployer/ansible_example.py
0 → 100644
View file @
219855d6
#!/usr/bin/env python
import
json
from
collections
import
namedtuple
from
ansible.parsing.dataloader
import
DataLoader
from
ansible.vars
import
VariableManager
from
ansible.inventory
import
Inventory
from
ansible.playbook.play
import
Play
from
ansible.executor.task_queue_manager
import
TaskQueueManager
from
ansible.plugins.callback
import
CallbackBase
import
ansible.executor.task_queue_manager
import
ansible.inventory
import
ansible.parsing.dataloader
import
ansible.playbook.play
import
ansible.plugins.callback
import
ansible.vars
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
the end of the execution, look into utilizing the ``json`` callback plugin
or writing your own custom callback plugin
"""
def
v2_runner_on_ok
(
self
,
result
,
**
kwargs
):
"""Print a json representation of the result
This method could store the result in an instance attribute for retrieval later
"""
host
=
result
.
_host
print
json
.
dumps
({
host
.
name
:
result
.
_result
})
class
Options
(
object
):
def
__init__
(
self
,
check
=
True
):
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
=
Options
(
check
=
False
)
# initialize needed objects
variable_manager
=
ansible
.
vars
.
VariableManager
()
loader
=
DataLoader
()
# Instantiate our ResultCallback for handling results as they come in
results_callback
=
ResultCallback
()
# 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
tqm
=
None
try
:
tqm
=
TaskQueueManager
(
inventory
=
inventory
,
variable_manager
=
variable_manager
,
loader
=
loader
,
options
=
options
,
passwords
=
None
,
#stdout_callback='json',
stdout_callback
=
results_callback
,
# Use our custom callback instead of the ``default`` callback plugin
#stdout_callback='default',
)
result
=
tqm
.
run
(
play
)
finally
:
if
tqm
is
not
None
:
tqm
.
cleanup
()
\ No newline at end of file
drip-deployer/ansible_playbook.py
View file @
219855d6
...
@@ -19,6 +19,8 @@ __author__ = 'S. Koulouzis'
...
@@ -19,6 +19,8 @@ __author__ = 'S. Koulouzis'
import
paramiko
,
os
import
paramiko
,
os
import
threading
import
threading
import
ansible.runner
from
ansible.playbook
import
PlayBook
def
install_prerequisites
(
vm
):
def
install_prerequisites
(
vm
):
try
:
try
:
...
@@ -30,10 +32,7 @@ def install_prerequisites(vm):
...
@@ -30,10 +32,7 @@ def install_prerequisites(vm):
sftp
=
ssh
.
open_sftp
()
sftp
=
ssh
.
open_sftp
()
sftp
.
chdir
(
'/tmp/'
)
sftp
.
chdir
(
'/tmp/'
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo sh /tmp/ansible_setup.sh"
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sudo sh /tmp/ansible_setup.sh"
)
stdout
.
read
()
stdout
.
read
()
#stdin, stdout, stderr = ssh.exec_command("sudo sh /tmp/ansible_setup.sh")
print
"Ansible prerequisites installed in:
%
s "
%
(
vm
.
ip
)
print
"Ansible prerequisites installed in:
%
s "
%
(
vm
.
ip
)
except
Exception
as
e
:
except
Exception
as
e
:
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
print
'
%
s:
%
s'
%
(
vm
.
ip
,
e
)
...
@@ -50,5 +49,9 @@ def run(vm_list,playbook):
...
@@ -50,5 +49,9 @@ def run(vm_list,playbook):
privatekey
=
vm
.
key
privatekey
=
vm
.
key
user
=
vm
.
user
user
=
vm
.
user
if
"ERROR"
in
ret
:
return
ret
if
"ERROR"
in
ret
:
return
ret
print
(
"ansible-playbook "
+
playbook
+
"-i "
+
ips
+
" --private-key="
+
privatekey
+
" --user="
+
user
)
# 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/playbook.yml
View file @
219855d6
fdsvvvvvvvvv
---
\ No newline at end of file
-
hosts
:
all
tasks
:
-
name
:
install sysbench
apt
:
name="{{ item }}" update_cache=yes state=latest
with_items
:
-
phoronix-test-suite
-
sysbench
-
expect
-
git
-
python-pexpect
become
:
true
-
name
:
Phoronix-test-suite accept User Agreement
command
:
expect -c "spawn phoronix-test-suite; expect \"Do you agree to these terms and wish to proceed \(Y/n\):\"; send \"Y\n\"; expect \"Enable anonymous usage / statistics reporting \(Y/n\):\"; send \"n\n\"; expect \"Enable anonymous statistical reporting of installed software / hardware \(Y/n\):\"; send \"n\n\"; interact;"
become
:
true
-
name
:
Install stream
command
:
phoronix-test-suite install-test stream
become
:
true
-
name
:
Install iozone
command
:
phoronix-test-suite install-test iozone
become
:
true
-
name
:
Count vCPU
command
:
nproc
register
:
vcpunumber
become
:
true
-
debug
:
msg="{{ vcpunumber.stdout }}"
-
name
:
Run sysbench
command
:
sysbench --test=cpu --cpu-max-prime=100000 --num-threads={{ vcpunumber.stdout }} run
register
:
sysbenchoutput
become
:
true
-
debug
:
msg="{{ sysbenchoutput.stdout }}"
-
local_action
:
copy content="{{ sysbenchoutput.stdout }}" dest="{{ resultslocation }}sysbench"
-
name
:
Run stream
command
:
expect -c "spawn phoronix-test-suite run-test stream; expect \"Type:\"; send \"4\n\"; expect \"\(Y/n\):\"; send \"n\n\"; interact;"
#command: ls -all
register
:
streamoutput
become
:
true
-
debug
:
msg="{{ streamoutput.stdout }}"
-
local_action
:
copy content="{{ streamoutput.stdout }}" dest="{{ resultslocation }}stream"
-
name
:
Run iozone
command
:
expect -c "spawn phoronix-test-suite run-test iozone; expect \"Record Size:\"; send \"2\n\"; expect \"File Size:\"; send \"2\n\"; expect \"Disk Test:\"; send \"3\n\"; expect \"\(Y/n\):\"; send \"n\n\"; interact;"
register
:
iozoneoutput
become
:
true
-
debug
:
msg="{{ iozoneoutput.stdout }}"
-
local_action
:
copy content="{{ iozoneoutput.stdout }}" dest="{{ resultslocation }}iozone"
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