Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Birin Sanchez
Shipwright - LDH Developer
Commits
209cae23
Commit
209cae23
authored
Nov 29, 2018
by
David Seaward
Browse files
Merge branch 'master' into 'master'
Master See merge request liberty/ldh_developer!3
parents
a3fd95f9
5d4cab06
Changes
1
Hide whitespace changes
Inline
Side-by-side
shipyard/shipyard
View file @
209cae23
...
...
@@ -23,10 +23,25 @@ Vagrant.configure("2") do |config|
libvirt.graphics_type = "spice"
libvirt.cpus = {cpus}
end
{hostname}.vm.provision "ansible" do |ansible|
ansible.playbook = "shim.yml"
end
end
end
"""
ansible_shim
=
"""
---
- hosts: all
become: yes
tasks:
- name: Shim file for ansible
file:
path: /etc/shipyard_shim.txt
state: touch
"""
XDG_CONFIG_HOME
=
Path
(
os
.
environ
[
'HOME'
],
'.config'
,
'ldh_developer'
,
'shipyard'
)
...
...
@@ -101,6 +116,8 @@ def create_box(hostname, ram, cpus):
ram
=
ram
,
cpus
=
cpus
,
))
# The Ansible shim
vagrant_wd
.
joinpath
(
'shim.tml'
).
open
(
mode
=
'w'
).
write
(
ansible_shim
)
# Execute vagrant with the generated vagrantfile
subprocess
.
run
([
'vagrant'
,
'up'
],
cwd
=
vagrant_wd
)
...
...
@@ -108,7 +125,7 @@ def create_box(hostname, ram, cpus):
@
only_if_box_exist
def
destroy_
box
(
hostname
):
def
destroy_
vm
(
hostname
):
"""
Destroy a box, or all
"""
...
...
@@ -120,10 +137,16 @@ def destroy_box(hostname):
@
only_if_box_exist
def
run_playbook
(
hostname
,
playbook
):
"""
run a playbook against
one of the boxes
run a
n Ansible
playbook against
this vm
"""
vagrant_wd
=
XDG_CONFIG_HOME
.
joinpath
(
hostname
)
subprocess
.
run
([
'vagrant'
,
'destroy'
],
cwd
=
vagrant_wd
)
inventory_file
=
vagrant_wd
.
joinpath
(
'.vagrant'
,
'provisioners'
,
'ansible'
,
'inventory'
,
'vagrant_ansible_inventory'
)
subprocess
.
run
([
'ansible-playbook'
,
'-u'
,
'vagrant'
,
'-i'
,
f
'
{
inventory_file
}
'
,
f
'
{
Path
(
playbook
).
resolve
()
}
'
],
cwd
=
vagrant_wd
)
@
only_if_box_exist
...
...
@@ -136,7 +159,7 @@ def start_vm(hostname):
@
only_if_box_exist
def
halt
(
hostname
):
def
halt
_vm
(
hostname
):
"""
Stops the vm with the provided hostname
"""
...
...
@@ -174,6 +197,7 @@ COMMANDS = {
'status'
:
"Prints the status of all the VM's managed by shipyard"
,
'create'
:
'Creates a new VM using vagrant and libvirt (KVM)'
,
'up'
:
'Start VM'
,
'halt'
:
'Stop/shutdown a VM'
,
'destroy'
:
'Destroy the VM and do cleanup'
,
'ssh'
:
'Connect to the vm using SSH'
,
'playbook'
:
'Run a playbook against a machine'
,
...
...
@@ -208,7 +232,8 @@ if __name__ == '__main__':
sub_parser
.
add_argument
(
'hostname'
,
help
=
'This is the hostname of the box'
)
if
cmd_args
.
command
==
'playbook'
:
sub_parser
.
add_argument
(
'--playbook'
,
help
=
'Path to the yml file'
,
required
=
True
)
sub_parser
.
usage
=
'shipyard playbook hostname path/to/playbook.yml'
sub_parser
.
add_argument
(
'playbook'
,
help
=
'The path to the playbook file'
)
sub_args
=
sub_parser
.
parse_args
(
sys
.
argv
[
2
:])
run_playbook
(
sub_args
.
hostname
,
sub_args
.
playbook
)
sys
.
exit
()
...
...
@@ -216,8 +241,10 @@ if __name__ == '__main__':
sub_args
=
sub_parser
.
parse_args
(
sys
.
argv
[
2
:])
if
cmd_args
.
command
==
'up'
:
start_vm
(
sub_args
.
hostname
)
if
cmd_args
.
command
==
'halt'
:
halt_vm
(
sub_args
.
hostname
)
elif
cmd_args
.
command
==
'destroy'
:
destroy_
box
(
sub_args
.
hostname
)
destroy_
vm
(
sub_args
.
hostname
)
elif
cmd_args
.
command
==
'ssh'
:
invoke_shell
(
sub_args
.
hostname
)
elif
cmd_args
.
command
==
'which'
:
...
...
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