README.md 7.41 KB
Newer Older
Noe Nieto's avatar
Noe Nieto committed
1
2
# The shipyard

3
The `shipyard` is a small wrapper around vagrant and libvirt that allows you to manage virtual machines easily. For most commands you only need to provide the hostname.
Noe Nieto's avatar
Noe Nieto committed
4
5


6
## Installation
Noe Nieto's avatar
Noe Nieto committed
7

8
9
10
11
First you need to setup you machine. Follow the [istructions to run the`shipyard_setup` script here](../start-here).


Now clone this repo,`cd` into `shipyard/`, and launch the command:
Noe Nieto's avatar
Noe Nieto committed
12
13

```bash
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
./shipyard 
```

Feel free to copy the script to `~/bin` or symlink it so you don't need to enter the directory every time you run the script.

## How it works

Shipyard uses `~/.config/ldh_developer/shipyard` as configuration directory.

Every folder inside the `shipyard` folder represents a vagrant box, so for a box with hostname `floyd` the `$VAGRANT_HOME` directory is `~/.config/lds_developer/shipyard/floyd`:


```bash
ls -l ~/.config/ldh_developer/shipyard/
total 8
drwxr-xr-x 3 nnieto nnieto 4.0K Nov 27 21:46 floyd/
```
The `floyd` folder contains two files (`Vagrantfile` and `shim.yml`) and the vagrant hidden folder(`.vagrant`). 

Once `shipyard` creates a box, you can manage it with the libvirt and vagrant tools of your choice. Recommended tools are:

- [GNOME Vagrant Indicator](https://github.com/fffilo/gnome-vagrant-indicator)
- virt-manager (apt install virt-manager)

## Commands

`shipyard` supports these commands:

- `status`: report the status of the virtual machines created/managed by `shipyard`.
- `create`: create a new VM. You only need to provide the hostname.
- `up`: starts a VM.
- `halt`:  stops a VM.
- `destroy`: destroys the VM
- `ssh`: opens a ssh session directly to the VM as `vagrant` user.
- `playbook`: provisions a VM with an ansible playbook.
- `which`: prints the configuration directory path of a VM.
- `open`: opens the configuration directory of a VM with the current file manager (nautilus, dolphin, etc.)

### The `status` command

Prints a summary of the state of all VM's managed by `shipyard`. Example:


```
$ shipyard status
hostname 	 State  	 IP Address
nina 	     running	 192.168.121.185
pinta   	 shutoff	 <N/A>
stmaria 	 running	 192.168.121.178
Total 3 machine(s)
$
```

### The `create` command

This command creates a new VM. You only need to provide the hostname. But you can specify the ram size and the number of cpus.

The following example creates a VM with the hostname `usoland`. The default values for ram size is 512 MB, and 1 CPU.

```
$ shipyard create usoland
Bringing machine 'usoland' up with 'libvirt' provider...
==> usoland: Checking if box 'debian/stretch64' is up to date...
[...]
==> usoland:  -- Memory:            512M
[...]
==> usoland:  -- Cpus:              1
[...]

```
The following example creates a VM with the hostname `usoland` with 4 cpus and 1GB of ram: 

```
$ shipyard create usoland --cpus 4 --ram 1024
Bringing machine 'usoland' up with 'libvirt' provider...
[...]
==> usoland:  -- Cpus:              4
[...]
==> usoland:  -- Memory:            1024M
[...]
==> usoland: Pruning invalid NFS exports. Administrator privileges will be required...
==> usoland: Creating shared folders metadata...
    usoland: Running ansible-playbook...
[...]

$
```
**Note**: Vagrant/libvirt need root access to create and modify networks on the machine. Vagrant will try to use sudo and will request your passowrd.


### The `up` and `halt` commands

Use these commands to start and shutdown the VM's. As an example, the previous section we created one vm. If we check the status we find that it's running.

```
$ shipyard status
hostname 	 State	 IP Address
usoland 	 running	 192.168.121.57
Total 1 machine(s)
$
```

Now, let's use the `halt` command.

``` 
shipyard halt usoland
==> usoland: Halting domain...
$
```

We can see that the VM status is `shutoff`:
```
$ shipyard status
hostname 	 State	 IP Address
usoland 	 shutoff	 <N/A>
Total 1 machine(s)

$
```

We use the `up` command to start the VM again.

```
$ shipyard up usoland
Bringing machine 'usoland' up with 'libvirt' provider...
==> usoland: Checking if box 'debian/stretch64' is up to date...
==> usoland: Starting domain.
==> usoland: Waiting for domain to get an IP address...
==> usoland: Waiting for SSH to become available...
==> usoland: Creating shared folders metadata...
==> usoland: Exporting NFS shared folders...
==> usoland: Preparing to edit /etc/exports. Administrator privileges will be required...
==> usoland: Mounting NFS shared folders...
==> usoland: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> usoland: flag to force provisioning. Provisioners marked to run always will still run.
$
Noe Nieto's avatar
Noe Nieto committed
150
151
```

152
Now `status` shows that the vm is running.
Noe Nieto's avatar
Noe Nieto committed
153

154
155
156
```
$ shipyard status
hostname 	 State	 IP Address
Noe Nieto's avatar
Typo    
Noe Nieto committed
157
usoland 	 running	 192.168.121.57
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Total 1 machine(s)

$
```

### The `ssh` command

The ssh command opens an ssh to the VM.

```bash
$ shipyard ssh usoland
Linux usoland 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Nov 30 07:26:45 2018 from 192.168.121.1
vagrant@usoland:~$ logout
Connection to 192.168.121.57 closed.

$
```

### The `which` command

The `which` command prints the full path to the `$VAGRANT_HOME` directory of the VM.

```
$ shipyard which usoland
/home/nnieto/.config/ldh_developer/shipyard/usoland

$
```

### The `open` command

This command opens a new window of your file manager pointing to the `$VAGRANT_HOME` of the VM.

```bash
./shipyard open --hostname=starone0
[... nautilis shows up ...]
```


### The `ansible` command

This command allows you to run an ansible playbook against one of the VMs. For example: I have two VM's managed by `shipyard`:

```
./shipyard status
hostname 	 State	 IP Address
usoland 	 shutoff	 <N/A>
going-merry 	 running	 192.168.121.89
Total 2 machine(s)
```

Let's install rust on`going-merry`. The playbook looks like this:

```yaml
---
- name: Rust Playbook
  become: yes
  hosts: all
  tasks:
    - name: Install Rust
      apt: name=rustc update_cache=yes
```

Let's save it as `rust.yml` and run the playbook against `going-merry`:

```
./shipyard playbook going-merry rust.yaml 

PLAY [Rust Playbook] *************************************************************************************

TASK [Gathering Facts] ***********************************************************************************
ok: [going-merry]

TASK [Install Rust] **************************************************************************************
changed: [going-merry]

PLAY RECAP ***********************************************************************************************
going-merry                      : ok=2    changed=1    unreachable=0    failed=0   

```

Now I can use `rustc` on the VM:

```bash
./shipyard ssh going-merry
Linux going-merry 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Nov 28 23:17:19 2018 from 192.168.121.1

vagrant@going-merry:~$ whereis rustc
rustc: /usr/bin/rustc /usr/share/rustc /usr/share/man/man1/rustc.1.gz

vagrant@going-merry:~$ logout
Connection to 192.168.121.89 closed.
```
Noe Nieto's avatar
Noe Nieto committed
267