Skip to content

Commit e22f9db

Browse files
authored
F #46: Improve infra role + Add persistent mounts (#84)
- Pre-run helpers python3 and cache in the infra playbook (fix). - Do NOT use pip, use system packages instead. - Use genisoimage instead of pycdlib. - Use the 'pc' machine type (fix). - Add a way to define passthrough filesystems (like virtiofs or 9p). - Add the helper/fstab role to manage persistent mounts.
1 parent 91aca39 commit e22f9db

12 files changed

Lines changed: 169 additions & 57 deletions

File tree

inventory/shared.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ all:
2929
NETWORK_MASK: 255.255.255.0
3030
GATEWAY: 172.20.0.1
3131
DNS: 1.1.1.1
32+
# Mount NFS share.
33+
fstab:
34+
- src: server:/var/lib/one/datastores
35+
path: /mnt
3236

3337
frontend:
3438
hosts:

playbooks/infra.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
---
22
- hosts: "{{ infra_group | d('infra') }}"
33
tags: [infra]
4+
collections:
5+
- opennebula.deploy
46
roles:
7+
- role: helper/python3
8+
59
- role: helper/facts
610
tags: [always]
711

12+
- role: helper/cache
13+
814
- role: infra

playbooks/pre.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@
3939

4040
- role: helper/keys
4141
tags: [keys]
42+
43+
- role: helper/fstab
44+
tags: [fstab]

roles/helper/fstab/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Role: opennebula.deploy.helper.fstab
2+
====================================
3+
4+
A role that populates `/etc/fstab` and mounts filesystems.
5+
6+
Requirements
7+
------------
8+
9+
N/A
10+
11+
Role Variables
12+
--------------
13+
14+
| Name | Type | Default | Example | Description |
15+
|---------|--------|---------|---------------|------------------------------|
16+
| `fstab` | `list` | `[]` | (check below) | A list of mount definitions. |
17+
18+
Dependencies
19+
------------
20+
21+
- `ansible.posix`
22+
23+
Example Playbook
24+
----------------
25+
26+
- hosts: frontend:node
27+
vars:
28+
fstab:
29+
- src: server:/var/lib/one/datastores
30+
path: /var/lib/one/datastores
31+
fstype: nfs
32+
opts: rw,relatime,comment=one-deploy
33+
roles:
34+
- role: opennebula.deploy.helper.fstab
35+
36+
License
37+
-------
38+
39+
Apache-2.0
40+
41+
Author Information
42+
------------------
43+
44+
[OpenNebula Systems](https://opennebula.io/)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
fstab: []

roles/helper/fstab/meta/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
collections:
3+
- opennebula.deploy
4+
- ansible.posix

roles/helper/fstab/tasks/main.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
- name: Install required OS packages
3+
ansible.builtin.package:
4+
name: "{{ (_common + _specific[ansible_os_family]) | select }}"
5+
vars:
6+
_common: []
7+
_specific:
8+
Debian:
9+
- "{{ 'nfs-common' if ('nfs' in _fstypes) else None }}"
10+
RedHat:
11+
- "{{ 'nfs-utils' if ('nfs' in _fstypes) else None }}"
12+
_fstypes: >-
13+
{{ fstab | d([])
14+
| map(attribute='fstype')
15+
| map('default', 'nfs')
16+
| map('lower') }}
17+
register: package
18+
until: package is success
19+
retries: 12
20+
delay: 5
21+
22+
- name: Add to fstab and mount filesystems
23+
ansible.posix.mount:
24+
src: "{{ item.src }}"
25+
path: "{{ item.path | d('/var/lib/one/datastores') }}"
26+
fstype: "{{ item.fstype | d('nfs') }}"
27+
opts: "{{ item.opts | d('rw,relatime,comment=one-deploy') }}"
28+
state: mounted
29+
loop: "{{ fstab }}"

roles/infra/README.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,49 @@ Pre-installed Libvirt software.
1111
Role Variables
1212
--------------
1313

14-
| Name | Type | Default | Example | Description |
15-
|--------------------------|-------|--------------------|---------------------|-------------------------------------------------------------------|
16-
| `frontend_group` | `str` | `frontend` | | Custom name of the Frontend group in the inventory. |
17-
| `infra_group` | `str` | `infra` | | Custom name of the Infra group in the inventory. |
18-
| | | | | |
19-
| `runtime_dir` | `str` | `/var/one-deploy/` | | Directory used to store QCOW2 and ISO images. |
20-
| `os_image_url` | `str` | (check below) | | HTTP(S) link to Debian/RedHat-like image running `one-contextd`. |
21-
| `os_image_size` | `str` | `20G` | | The size to which one-deploy will **try** to adjust the OS image. |
22-
| `memory_KiB` | `str` | `2097152` | | Memory amount to be set in XML in Libvirt. |
23-
| `vcpu_static` | `str` | `1` | | VCPU amount to be set in XML in Libvirt. |
24-
| `vnc_max_port` | `str` | `65535` | | Upper limit for VNC ports to start counting-down from. |
25-
| `infra_bridge` | `str` | `br0` | | Pre-defined bridge interface to insert VM NICs to. |
26-
| | | | | |
27-
| `infra_hostname` | `str` | | `n1a1` | Defines on which HV machine the Front-end VM should be deployed. |
28-
| `context.ETH0_DNS` | `str` | | `1.1.1.1` | DNS server. |
29-
| `context.ETH0_GATEWAY` | `str` | | `10.2.50.1` | Gateway. |
30-
| `context.ETH0_IP` | `str` | | `10.2.50.100` | IPv4 address to be set on eth0. |
31-
| `context.ETH0_MAC` | `str` | | `02:01:0a:02:32:64` | MAC address to be set on eth0 (**MUST** match MAC set in XML.) |
32-
| `context.ETH0_MASK` | `str` | | `255.255.255.0` | Network mask. |
33-
| `context.ETH0_NETWORK` | `str` | | `10.2.50.0` | Network address. |
34-
| `context.GROW_FS` | `str` | `/` | | Filesystems to grow. |
35-
| `context.PASSWORD` | `str` | `opennebula` | | Root's password. |
36-
| `context.SET_HOSTNAME` | `str` | name of the FE VM | | Hostname. |
37-
| `context.SSH_PUBLIC_KEY` | `str` | | (check below) | Root's extra authorized keys. |
14+
| Name | Type | Default | Example | Description |
15+
|--------------------------|--------|--------------------|---------------------|-------------------------------------------------------------------|
16+
| `frontend_group` | `str` | `frontend` | | Custom name of the Frontend group in the inventory. |
17+
| `infra_group` | `str` | `infra` | | Custom name of the Infra group in the inventory. |
18+
| | | | | |
19+
| `runtime_dir` | `str` | `/var/one-deploy/` | | Directory used to store QCOW2 and ISO images. |
20+
| `os_image_url` | `str` | (check below) | | HTTP(S) link to Debian/RedHat-like image running `one-contextd`. |
21+
| `os_image_size` | `str` | `20G` | | The size to which one-deploy will **try** to adjust the OS image. |
22+
| `memory_KiB` | `str` | `2097152` | | Memory amount to be set in XML in Libvirt. |
23+
| `vcpu_static` | `str` | `1` | | VCPU amount to be set in XML in Libvirt. |
24+
| `vnc_max_port` | `str` | `65535` | | Upper limit for VNC ports to start counting-down from. |
25+
| `infra_bridge` | `str` | `br0` | | Pre-defined bridge interface to insert VM NICs to. |
26+
| `passthrough_fs` | `list` | `[]` | (check below) | Shared HV filesystems to attach to the Front-end VMs. |
27+
| | | | | |
28+
| `infra_hostname` | `str` | | `n1a1` | Defines on which HV machine the Front-end VM should be deployed. |
29+
| `context.ETH0_DNS` | `str` | | `1.1.1.1` | DNS server. |
30+
| `context.ETH0_GATEWAY` | `str` | | `10.2.50.1` | Gateway. |
31+
| `context.ETH0_IP` | `str` | | `10.2.50.100` | IPv4 address to be set on eth0. |
32+
| `context.ETH0_MAC` | `str` | | `02:01:0a:02:32:64` | MAC address to be set on eth0 (**MUST** match MAC set in XML.) |
33+
| `context.ETH0_MASK` | `str` | | `255.255.255.0` | Network mask. |
34+
| `context.ETH0_NETWORK` | `str` | | `10.2.50.0` | Network address. |
35+
| `context.GROW_FS` | `str` | `/` | | Filesystems to grow. |
36+
| `context.PASSWORD` | `str` | `opennebula` | | Root's password. |
37+
| `context.SET_HOSTNAME` | `str` | name of the FE VM | | Hostname. |
38+
| `context.SSH_PUBLIC_KEY` | `str` | | (check below) | Root's extra authorized keys. |
3839

3940
**NOTE**: The `infra_hostname` and `context` dictionary should be set for members of the `frontend` group (please check the `inventory/infra.yml` example).
4041

4142
Dependencies
4243
------------
4344

44-
- `community.general`
4545
- `community.libvirt`
4646

4747
Example Playbook
4848
----------------
4949

5050
- hosts: infra
5151
vars:
52-
os_image_url: https://d24fmfybwxpuhu.cloudfront.net/ubuntu2204-6.8.1-1-20240131.qcow2
52+
os_image_url: https://d24fmfybwxpuhu.cloudfront.net/ubuntu2204-6.10.0-1-20240514.qcow2
53+
passthrough_fs:
54+
- driver_type: virtiofs
55+
source_dir: /var/lib/one/datastores
56+
target_dir: /var/lib/one/datastores
5357
roles:
5458
- role: opennebula.deploy.helper.facts
5559
- role: opennebula.deploy.infra

roles/infra/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ memory_KiB: 2097152 # 2 GiB
66
vcpu_static: 1
77
vnc_max_port: 65535
88
infra_bridge: br0
9+
passthrough_fs: []

roles/infra/meta/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
22
collections:
33
- opennebula.deploy
4-
- community.general
54
- community.libvirt

0 commit comments

Comments
 (0)