Compare commits
4
Commits
main
..
e3de9c111c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3de9c111c | ||
|
|
4da3fbfc7f | ||
|
|
6c402ce9bd | ||
|
|
7473233813 |
No files matched your search
@@ -1,47 +1,17 @@
|
||||
# Provision one Proxmox VM with Semaphore
|
||||
|
||||
Run `ansible/proxmox/provision_vm.yml` as a Semaphore Ansible task with inventory `localhost ansible_connection=local`. It clones one cloud-init template, configures the new VM before boot, then connects to the guest by FQDN.
|
||||
Create an Ansible task template for `ansible/proxmox/provision_vm.yml` with a localhost inventory (`localhost ansible_connection=local`). It clones a cloud-init QEMU template, configures the VM and starts it.
|
||||
|
||||
## Prerequisites
|
||||
The Semaphore server gets `proxmoxer>=2.3,<3` and `requests>=2.31,<3` from `docker/semaphore/requirements.txt` (mounted from `/appli/docker/semaphore/requirements.txt` to `/etc/semaphore/requirements.txt`); the image installs these on container startup, not merely on mount. Semaphore automatically installs the adjacent `ansible/proxmox/requirements.yml` (`community.proxmox:2.0.0`) unless **Skip Galaxy install** is enabled.
|
||||
|
||||
- The template needs a bootable `scsi0`, a `scsi1` cloud-init drive, Python 3, `cloud-init`, `timeout`, SSH and network access. It does not need the QEMU guest agent enabled.
|
||||
- The guest needs `timedatectl`, `tzdata`, apt access and noninteractive sudo for `vm_user` to set its timezone and install/start the agent.
|
||||
- The Semaphore runner must trust the Proxmox CA and have a verified guest SSH host key in `known_hosts`. Do not disable TLS or SSH host-key verification. Confirm the DNS record belongs to the new VM before connecting; a stale record could point to another host.
|
||||
- Select an SSH Key Store **user credential on the task inventory** matching an authorized public key for `vm_user`. Check that the same invocation makes this credential available to the dynamically added guest in your installed Semaphore version. The Proxmox API token is separate.
|
||||
- The Semaphore image installs `proxmoxer>=2.3,<3` and `requests>=2.31,<3` from `docker/semaphore/requirements.txt` on startup (mounted at `/etc/semaphore/requirements.txt`). Semaphore installs `ansible/proxmox/requirements.yml` (`community.proxmox:2.0.0`) unless **Skip Galaxy install** is enabled.
|
||||
In a Semaphore Variable Group, set fixed `proxmox_api_host` (hostname, not URL), `proxmox_node`, `vm_template_id`, `vm_storage`, `vm_user`, and `vm_ssh_public_key` (public key only). Set `proxmox_api_token_id` (full `user@realm!token`) and `proxmox_api_token_secret` in the group's **Secrets** tab, not the survey. Optional fixed values: `proxmox_api_port` (default 8006) and `vm_ipconfig0` (default `ip=dhcp`). Trust the Proxmox CA in the runner; TLS verification stays enabled.
|
||||
|
||||
## Semaphore variables
|
||||
|
||||
Put these fixed values in a Variable Group:
|
||||
|
||||
| Variable | Value |
|
||||
| Survey variable | Default |
|
||||
| --- | --- |
|
||||
| `proxmox_api_host` | Hostname, not a URL |
|
||||
| `vm_template_id`, `vm_storage`, `vm_user` | Template, destination storage and guest user |
|
||||
| `vm_ssh_public_key` | One or more complete public keys, separated by newlines; include the key matching the selected SSH credential |
|
||||
| `proxmox_api_port` | Optional; defaults to `8006` |
|
||||
| `vm_ipconfig0` | Optional; defaults to `ip=dhcp` |
|
||||
|
||||
Put `proxmox_api_token_id` (full `user@realm!token`) and `proxmox_api_token_secret` in the Variable Group's **Secrets** tab, not the survey.
|
||||
|
||||
Survey inputs:
|
||||
|
||||
| Variable | Default |
|
||||
| --- | --- |
|
||||
| `vm_hostname` | Required unique short DNS label (no dots) |
|
||||
| `vm_hostname` | Required; unique name |
|
||||
| `vm_cpu` | `1` core |
|
||||
| `vm_ram_gib` | `2` GiB |
|
||||
| `vm_disk_gib` | `4` GiB, absolute disk size |
|
||||
| `vm_vlan` | `vlan66` bridge/VNet name |
|
||||
|
||||
Only `vlan66` maps to a DNS suffix (`lab.vezpi.com`); other VLANs fail before cloning. DHCP/DNS must publish `<hostname>.lab.vezpi.com` for that VNet.
|
||||
|
||||
## What happens
|
||||
|
||||
1. The playbook rejects an invalid or existing hostname, then finds the template's current node and clones it. It enables the clone's virtio guest-agent channel before first boot, regardless of template configuration.
|
||||
2. It waits for DNS, port 22, an Ansible connection and cloud-init. Cloud-init exit code `0` is accepted; degraded exit code `2` is accepted with a warning. Other codes, incomplete status and timeouts fail.
|
||||
3. On the guest it sets the display timezone to `Europe/Paris` (CET/CEST), installs `qemu-guest-agent` and starts its device-activated service. It does not change RTC/NTP, manually enable the static unit, configure sudo or reboot.
|
||||
|
||||
New clones use `vm_cpu_model` (default `x86-64-v2-AES`, overridable via extra vars) before first boot; every destination host must support the selected model. Existing VMs and templates are unchanged.
|
||||
|
||||
A failure leaves the new VM intact for inspection. Playbook success does **not** prove agent communication: on the VM's actual Proxmox node, run `qm agent <NEW_VMID> ping`. A successful exit with no error is sufficient, even if the response is empty.
|
||||
Use a template with bootable `scsi0` and a `scsi1` cloud-init drive; partial failures are not automatically deleted, and starting the VM does not guarantee guest cloud-init readiness.
|
||||
@@ -82,7 +82,7 @@
|
||||
qm create {{ template_vmid }}
|
||||
--memory {{ template_memory }}
|
||||
--core {{ template_cores }}
|
||||
--net0 virtio,bridge=vlan66
|
||||
--net0 virtio,bridge=vmbr0
|
||||
--scsihw virtio-scsi-pci
|
||||
--bios ovmf
|
||||
--machine q35
|
||||
@@ -98,6 +98,9 @@
|
||||
- name: Set boot order to the primary disk
|
||||
ansible.builtin.command: qm set {{ template_vmid }} --boot order=scsi0
|
||||
|
||||
- name: Add serial console for cloud-init consoles
|
||||
ansible.builtin.command: qm set {{ template_vmid }} --serial0 socket --vga serial0
|
||||
|
||||
- name: Convert the VM to a template
|
||||
ansible.builtin.command: qm template {{ template_vmid }}
|
||||
|
||||
|
||||
@@ -6,13 +6,10 @@
|
||||
vars:
|
||||
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||
vm_cpu: 1
|
||||
vm_cpu_model: x86-64-v2-AES
|
||||
vm_ram_gib: 2
|
||||
vm_disk_gib: 4
|
||||
vm_vlan: vlan66
|
||||
vm_ipconfig0: ip=dhcp
|
||||
vm_dns_domains:
|
||||
vlan66: lab.vezpi.com
|
||||
module_defaults:
|
||||
group/community.proxmox.proxmox:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
@@ -22,12 +19,29 @@
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
validate_certs: true
|
||||
tasks:
|
||||
- name: Validate hostname and DNS mapping before using the API
|
||||
- name: Validate inputs before using the API
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- vm_hostname is defined and vm_hostname is match('^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$')
|
||||
- vm_vlan in vm_dns_domains
|
||||
fail_msg: A short hostname and a known VLAN/DNS suffix are required; no VM was created.
|
||||
- proxmox_api_host is defined and proxmox_api_host | length > 0
|
||||
- proxmox_node is defined and proxmox_node | length > 0
|
||||
- vm_template_id is defined and vm_template_id | string is match('^[0-9]+$')
|
||||
- vm_hostname is defined and vm_hostname is match('^[a-zA-Z0-9][a-zA-Z0-9.-]*$')
|
||||
- vm_storage is defined and vm_storage | length > 0
|
||||
- vm_vlan is defined and vm_vlan is match('^[a-zA-Z0-9_.-]+$')
|
||||
- vm_user is defined and vm_user | length > 0
|
||||
- vm_ssh_public_key is defined and vm_ssh_public_key | length > 0
|
||||
- vm_cpu | string is match('^[0-9]+$') and vm_cpu | int > 0
|
||||
- vm_ram_gib | string is match('^[0-9]+$') and vm_ram_gib | int > 0
|
||||
- vm_disk_gib | string is match('^[0-9]+$') and vm_disk_gib | int > 0
|
||||
fail_msg: Required VM inputs are missing or invalid; no VM was created.
|
||||
|
||||
- name: Validate API token inputs
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- proxmox_api_token_id is defined and proxmox_api_token_id is match('^[^!]+![^!]+$')
|
||||
- proxmox_api_token_secret is defined and proxmox_api_token_secret | length > 0
|
||||
fail_msg: Configure a Proxmox API token ID and secret in the Semaphore variable group secrets.
|
||||
no_log: true
|
||||
|
||||
- name: Look up requested hostname across the cluster
|
||||
community.proxmox.proxmox_vm_info:
|
||||
@@ -48,23 +62,23 @@
|
||||
register: source_vm
|
||||
no_log: true
|
||||
|
||||
- name: Require a cloud-init-ready template on its current node
|
||||
- name: Require a cloud-init-ready template on the selected node
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- source_vm.proxmox_vms | length == 1
|
||||
- source_vm.proxmox_vms[0].node is defined
|
||||
- source_vm.proxmox_vms[0].node == proxmox_node
|
||||
- source_vm.proxmox_vms[0].template | bool
|
||||
- source_vm.proxmox_vms[0].config.scsi0 is defined
|
||||
- source_vm.proxmox_vms[0].config.scsi1 is defined
|
||||
- "'cloudinit' in source_vm.proxmox_vms[0].config.scsi1"
|
||||
fail_msg: "Template {{ vm_template_id }} must resolve uniquely to a QEMU template with a node, scsi0 and a scsi1 cloud-init drive; no VM was created."
|
||||
fail_msg: "Template {{ vm_template_id }} must be a QEMU template on {{ proxmox_node }} with scsi0 and a scsi1 cloud-init drive; no VM was created."
|
||||
|
||||
- name: Clone template into a new VM
|
||||
- name: Clone full VM onto requested storage
|
||||
community.proxmox.proxmox_kvm:
|
||||
clone: source-template
|
||||
vmid: "{{ vm_template_id }}"
|
||||
name: "{{ vm_hostname }}"
|
||||
node: "{{ source_vm.proxmox_vms[0].node }}"
|
||||
node: "{{ proxmox_node }}"
|
||||
storage: "{{ vm_storage }}"
|
||||
full: true
|
||||
state: present
|
||||
@@ -76,6 +90,8 @@
|
||||
that:
|
||||
- cloned_vm.changed
|
||||
- cloned_vm.vmid is defined
|
||||
- cloned_vm.vmid | string is match('^[0-9]+$')
|
||||
- cloned_vm.vmid | int >= 100
|
||||
- cloned_vm.vmid | int != vm_template_id | int
|
||||
fail_msg: >-
|
||||
Clone did not return a valid new VMID (possibly allocated concurrently);
|
||||
@@ -84,11 +100,10 @@
|
||||
- name: Configure VM before first boot
|
||||
community.proxmox.proxmox_kvm:
|
||||
vmid: "{{ cloned_vm.vmid }}"
|
||||
node: "{{ source_vm.proxmox_vms[0].node }}"
|
||||
node: "{{ proxmox_node }}"
|
||||
update: true
|
||||
update_unsafe: true # Needed to replace net0 on this newly cloned VM.
|
||||
cores: "{{ vm_cpu }}"
|
||||
cpu: "{{ vm_cpu_model }}"
|
||||
memory: "{{ vm_ram_gib | int * 1024 }}"
|
||||
net:
|
||||
net0: "virtio,bridge={{ vm_vlan }}"
|
||||
@@ -96,11 +111,10 @@
|
||||
ipconfig0: "{{ vm_ipconfig0 }}"
|
||||
ciuser: "{{ vm_user }}"
|
||||
sshkeys: "{{ vm_ssh_public_key }}"
|
||||
agent: "enabled=1,type=virtio"
|
||||
state: present
|
||||
no_log: true
|
||||
|
||||
- name: Resize VM disk to requested size
|
||||
- name: Grow cloned scsi0 disk to requested size
|
||||
community.proxmox.proxmox_disk:
|
||||
vmid: "{{ cloned_vm.vmid }}"
|
||||
disk: scsi0
|
||||
@@ -108,85 +122,12 @@
|
||||
state: resized
|
||||
no_log: true
|
||||
|
||||
- name: Start VM
|
||||
- name: Start configured VM
|
||||
community.proxmox.proxmox_kvm:
|
||||
vmid: "{{ cloned_vm.vmid }}"
|
||||
state: started
|
||||
no_log: true
|
||||
|
||||
- name: Wait for guest DNS publication
|
||||
ansible.builtin.command: getent ahosts "{{ vm_hostname }}.{{ vm_dns_domains[vm_vlan] }}"
|
||||
register: guest_dns
|
||||
changed_when: false
|
||||
until: guest_dns.rc == 0 and guest_dns.stdout | length > 0
|
||||
retries: 20
|
||||
delay: 15
|
||||
|
||||
- name: Wait for guest SSH port
|
||||
ansible.builtin.wait_for:
|
||||
host: "{{ vm_hostname }}.{{ vm_dns_domains[vm_vlan] }}"
|
||||
port: 22
|
||||
connect_timeout: 5
|
||||
timeout: 180
|
||||
sleep: 5
|
||||
|
||||
- name: Add VM to dynamic inventory
|
||||
ansible.builtin.add_host:
|
||||
name: "{{ vm_hostname }}.{{ vm_dns_domains[vm_vlan] }}"
|
||||
groups: provisioned_vm
|
||||
ansible_connection: ssh
|
||||
ansible_user: "{{ vm_user }}"
|
||||
ansible_ssh_timeout: 10
|
||||
provisioned_vmid: "{{ cloned_vm.vmid }}"
|
||||
|
||||
- name: Verify cloud-init and Ansible on the new guest
|
||||
hosts: provisioned_vm
|
||||
gather_facts: false
|
||||
vars:
|
||||
vm_timezone: Europe/Paris
|
||||
tasks:
|
||||
- name: Wait for guest to be available
|
||||
ansible.builtin.wait_for_connection:
|
||||
connect_timeout: 10
|
||||
sleep: 5
|
||||
timeout: 180
|
||||
|
||||
- name: Wait for cloud-init status
|
||||
ansible.builtin.command: timeout 300 cloud-init status --wait --long
|
||||
register: cloudinit_wait
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Show cloud-init wait diagnostics
|
||||
- name: Report submitted VMID
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "stdout: {{ cloudinit_wait.stdout | trim }}"
|
||||
- "stderr: {{ cloudinit_wait.stderr | trim }}"
|
||||
when: cloudinit_wait.rc == 2
|
||||
|
||||
- name: Assert cloud-init completion
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- cloudinit_wait.rc in [0, 2]
|
||||
- "cloudinit_wait.stdout is search('(?m)^status: done\\s*$')"
|
||||
fail_msg: "VMID {{ provisioned_vmid }} cloud-init status is not complete (rc {{ cloudinit_wait.rc }}); VM left intact for inspection."
|
||||
|
||||
- name: Set guest timezone
|
||||
ansible.builtin.command: timedatectl set-timezone "{{ vm_timezone }}"
|
||||
become: true
|
||||
|
||||
- name: Install QEMU guest agent
|
||||
ansible.builtin.apt:
|
||||
name: qemu-guest-agent
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Start QEMU guest agent
|
||||
ansible.builtin.service:
|
||||
name: qemu-guest-agent
|
||||
state: started
|
||||
become: true
|
||||
|
||||
- name: Report verified guest readiness
|
||||
ansible.builtin.debug:
|
||||
msg: "VMID {{ provisioned_vmid }} at {{ inventory_hostname }} completed cloud-init."
|
||||
msg: "VMID {{ cloned_vm.vmid }} start requested; cloud-init completion is not checked."
|
||||
@@ -1,6 +1,6 @@
|
||||
services:
|
||||
server:
|
||||
image: gitea/gitea:28
|
||||
image: gitea/gitea:1.27
|
||||
container_name: gitea_server
|
||||
restart: always
|
||||
volumes:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
services:
|
||||
homeassistant:
|
||||
image: homeassistant/home-assistant:2026.10
|
||||
image: homeassistant/home-assistant:2026.9
|
||||
container_name: homeassistant_core
|
||||
hostname: homeassistant_core
|
||||
volumes:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
services:
|
||||
network_application:
|
||||
image: lscr.io/linuxserver/unifi-network-application:10.6.109-ls152
|
||||
image: lscr.io/linuxserver/unifi-network-application:10.6.101-ls143
|
||||
container_name: unifi_network_application
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
@@ -31,8 +31,7 @@ variable "vm_user_sshkeys" {
|
||||
type = list(string)
|
||||
default = [
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID62LmYRu1rDUha3timAIcA39LtcIOny1iAgFLnxoBxm vez@bastion",
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHovfHKpqTvwj5zrcSuSZALa8iiH6qBvE5dyJCz9eQ2k vez@surface",
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG9bx04oxnZTmMm/7U9lUlhZM64xIMUSx48JiwxUH86x semaphore"
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHovfHKpqTvwj5zrcSuSZALa8iiH6qBvE5dyJCz9eQ2k vez@surface"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user