Skip to content

Commit 64a40ec

Browse files
authored
Merge pull request #4 from jhuesser/generalize
Generalize to a working setup
2 parents 1c451e1 + ad72467 commit 64a40ec

File tree

16 files changed

+105
-39
lines changed

16 files changed

+105
-39
lines changed

ansible/inventory/group_vars/client.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ nomad_vault_addr: "https://{{ server_ip }}:8200"
66
nomad_common_name: "client.global.nomad"
77
nomad_ip_sans: "127.0.0.1, {{ client_ip }}"
88

9-
nfs_share_mounts:
10-
- src: "10.10.10.102:/home/debian/apps/prod-apps"
11-
path: "/mnt/storage"
12-
opts: "defaults,bg,intr,_netdev,retry=3"
13-
state: mounted
14-
- src: "10.10.10.102:/home/debian/syncthing/sync/books"
15-
path: "/mnt/books"
16-
opts: "defaults,bg,intr,_netdev,retry=3"
17-
state: mounted
18-
- src: "10.10.10.102:/home/debian/syncthing/sync/paper"
19-
path: "/mnt/paper"
20-
opts: "defaults,bg,intr,_netdev,retry=3"
21-
state: mounted
9+
#nfs_share_mounts:
10+
# - src: "10.10.10.102:/home/debian/apps/prod-apps"
11+
# path: "/mnt/storage"
12+
# opts: "defaults,bg,intr,_netdev,retry=3"
13+
# state: mounted
14+
# - src: "10.10.10.102:/home/debian/syncthing/sync/books"
15+
# path: "/mnt/books"
16+
# opts: "defaults,bg,intr,_netdev,retry=3"
17+
# state: mounted
18+
# - src: "10.10.10.102:/home/debian/syncthing/sync/paper"
19+
# path: "/mnt/paper"
20+
# opts: "defaults,bg,intr,_netdev,retry=3"
21+
# state: mounted

ansible/inventory/group_vars/prod.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
2-
# server_ip: "{{ hostvars[groups['prod'] | difference(groups['client']) | first]['ansible_default_ipv4']['address'] }}"
3-
server_ip: "10.10.10.110"
4-
client_ip: "10.10.10.111"
2+
server_ip: "{{ hostvars[groups['prod'] | difference(groups['client']) | first]['ansible_default_ipv4']['address'] }}"
3+
client_ip: "{{ hostvars[groups['prod'] | difference(groups['server']) | first]['ansible_default_ipv4']['address'] }}"
54
ansible_user: "debian"
65

76
# ssl

ansible/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@
1919
- role: nomad
2020

2121
tasks:
22+
- name: Verify services are running
23+
ansible.builtin.systemd:
24+
name: "{{ item }}"
25+
state: started
26+
loop:
27+
- consul-template
28+
29+
- name: Wait for consul-template to become active
30+
ansible.builtin.command: systemctl is-active consul-template
31+
register: consul_template_status
32+
retries: 50
33+
delay: 3
34+
until: consul_template_status.stdout == "active"
35+
changed_when: false
36+
37+
2238
- name: Goss smoke test
2339
import_role:
2440
name: kencx.ansible_collection.goss

ansible/playbooks/common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@
4343
- name: Goss validation
4444
role: kencx.ansible_collection.goss
4545
vars:
46-
goss_dir: "./goss"
46+
goss_dir: "{{ playbook_dir }}/../goss"
4747
goss_file: "base.yml"

ansible/roles/nomad/templates/nomad.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ User=nomad
1414
Group=nomad
1515
{% endif %}
1616

17-
ExecReload=/bin/kill -HUP $MAINPID
17+
ExecReload=/bin/systemctl restart nomad.service
1818
{% if nomad_server %}
1919
{% if nomad_vault_integration %}
2020
Type=forking

ansible/roles/vault/tasks/init.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@
7777
- vault_init_json is defined
7878
- vault_init_json.root_token is defined
7979

80+
- name: Wait for Vault to be initialized, unsealed and have a leader (if HA)
81+
command: vault status -format=json
82+
register: vault_status_raw
83+
retries: 20
84+
delay: 3
85+
until: >
86+
vault_status_raw.rc == 0 and
87+
(vault_status_raw.stdout | from_json).initialized and
88+
not (vault_status_raw.stdout | from_json).sealed and
89+
(
90+
not ((vault_status_raw.stdout | from_json).ha_enabled)
91+
or
92+
(((vault_status_raw.stdout | from_json).leader_address | default('')) != '')
93+
)
94+
changed_when: false
95+
failed_when: vault_status_raw.rc != 0
96+
8097
- name: Login with root token
8198
shell:
8299
cmd: vault login --format json {{ vault_root_token }}
@@ -127,6 +144,8 @@
127144
vault_token: "{{ vault_root_token }}"
128145
vault_address: "https://{{ ansible_default_ipv4.address }}:8200"
129146
vault_ca_cert_file: "{{ vault_terraform_cert_dir }}/vault-ca.crt"
147+
admin_password: "{{ vault_admin_password }}"
148+
kvuser_password: "{{ vault_kvuser_password }}"
130149
delegate_to: localhost
131150

132151
- name: Provision Vault secrets with Terraform provider

ansible/roles/vault/templates/vault.hcl.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
disable_mlock = false
12
storage "raft" {
23
path = "{{ vault_data_dir }}"
34
node_id = "{{ ansible_hostname }}"

bin/import-cloud-image

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
help() {
6-
echo "Usage: $0 [--debug|--force] [URL] [FILENAME]"
6+
echo "Usage: $0 [--debug|--force] [URL] [FILENAME] [VMID] [NET_BRIDGE] [DATASTORE]"
77
exit 1
88
}
99

@@ -29,7 +29,7 @@ IMG_DIR="/var/lib/vz/images"
2929
FILENAME="$2"
3030
IMG_PATH="$IMG_DIR/$FILENAME"
3131

32-
VMID=9001
32+
VMID=$3
3333
TEMPLATE_NAME=${FILENAME%.*}
3434
DESCRIPTION="$(
3535
cat <<EOF
@@ -45,9 +45,9 @@ EOF
4545
MEMORY=512
4646
CORES=1
4747
SOCKETS=1
48-
NET_BRIDGE="vmbr1"
48+
NET_BRIDGE=$4
4949
DISK_SIZE="4G"
50-
DISK_STORE="volumes"
50+
DISK_STORE=$5
5151

5252
install -m 0755 -d "$IMG_DIR"
5353
if [[ -e $IMG_PATH ]]; then

docs/src/getting_started.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,35 @@ import a cloud image and turn it into a new template.
3838
> - cloud-init installed
3939
> - qemu-guest-agent installed
4040
41-
1. (Optional) Run the `bin/import-cloud-image` [script](./images/cloud_image.html#script) to import a new cloud image:
41+
1. (Optional) Run the `bin/import-cloud-image` [script](./images/cloud_image.html#script) on your proxmox node to import a new cloud image:
4242

4343
```bash
44-
$ import-cloud-image [URL]
44+
$ import-cloud-image [URL] [FILENAME] [VMID] [NET_BRIDGE] [DATASTORE]
45+
# Eg: import-cloud-image https://cdimage.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 debian12cloud 9000 vmbr0 lvm_local
4546
```
4647

47-
2. Navigate to `packer/base-clone`
48+
2. Navigate to `packer/base-clone` on your control node
4849

4950
>**Tip**: Use the `bin/generate-vars` script to quickly generate variable files
5051
>in `packer` and `terraform` subdirectories.
5152
5253
3. Populate the necessary variables in `auto.pkrvars.hcl`:
5354

5455
```hcl
55-
proxmox_url = "https://<PVE_IP>:8006/api2/json"
56-
proxmox_username = "<user>@pam"
57-
proxmox_password = "<password>"
56+
proxmox_url = "https://<PVE_IP>:8006/api2/json"
57+
proxmox_username = "<user>@pam"
58+
proxmox_password = "<password>"
59+
proxmox_node = "node_name" # Visible in the GUI sidebar
60+
proxmox_storage_pool = "<pool_name> # Eg. local_lvm
61+
proxmox_bridge = "<bridge_name>" # Eg. vmbr0
62+
5863
5964
clone_vm = "<cloud-image-name>"
6065
vm_name = "<new-template-name>"
61-
vm_id = 5000
66+
vm_id = 5000 # ID of the template created by packer
67+
68+
ip_address = "<ip_address>"
69+
gateway = "<gateway_address>"
6270
6371
ssh_username = "debian"
6472
ssh_public_key_path = "/path/to/public/key"
@@ -88,6 +96,7 @@ provider to provision virtual machines from our Packer templates.
8896
```hcl
8997
proxmox_ip = "https://<PVE_IP>:8006/api2/json"
9098
proxmox_api_token = "<API_TOKEN>"
99+
target_node = "<proxmox_node_name>" # name of the proxmox cluster node to deploy the VM on
91100
92101
template_id = 5000
93102
ip_gateway = "10.10.10.1"
@@ -117,7 +126,6 @@ clients = [
117126
]
118127
119128
ssh_user = "debian"
120-
ssh_private_key_file = "/path/to/ssh/private/key"
121129
ssh_public_key_file = "/path/to/ssh/public/key"
122130
```
123131

@@ -169,6 +177,8 @@ $ ansible-inventory --graph --vars
169177
>**Note**: The `nfs_share_mounts` variable in `inventory/group_vars/client.yml`
170178
>should be modified or removed if not required
171179
180+
>**Note**: Check `ansible/roles/common/defaults/main.yml`to customize additional settings, like timezone
181+
172182
4. Run the playbook:
173183

174184
```bash

packer/base-clone/main.pkr.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ source "proxmox-clone" "base" {
3131

3232
qemu_agent = true
3333
cloud_init = true
34-
cloud_init_storage_pool = "volumes"
34+
cloud_init_storage_pool = var.proxmox_storage_pool
3535

3636
vm_id = var.vm_id
3737
vm_name = local.vm_name
@@ -44,7 +44,7 @@ source "proxmox-clone" "base" {
4444
scsi_controller = "virtio-scsi-pci"
4545

4646
network_adapters {
47-
bridge = "vmbr1"
47+
bridge = var.proxmox_bridge
4848
model = "virtio"
4949
}
5050

0 commit comments

Comments
 (0)