Compare commits
14
Commits
f4909858bf
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ae0b7a61b | ||
|
|
fff1434331 | ||
|
|
37cc21e450 | ||
|
|
c53a59e60a | ||
|
|
9557b37603 | ||
|
|
d019088f6a | ||
|
|
53f4d27601 | ||
|
|
5148019f9d | ||
|
|
5222e6cd6c | ||
|
|
843d1bda63 | ||
|
|
6927c98e01 | ||
|
|
f1c2852bf4 | ||
|
|
0b57391c38 | ||
|
|
2f60045469 |
No files matched your search
@@ -0,0 +1,47 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- 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.
|
||||||
|
|
||||||
|
## Semaphore variables
|
||||||
|
|
||||||
|
Put these fixed values in a Variable Group:
|
||||||
|
|
||||||
|
| Variable | Value |
|
||||||
|
| --- | --- |
|
||||||
|
| `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_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.
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
qm create {{ template_vmid }}
|
qm create {{ template_vmid }}
|
||||||
--memory {{ template_memory }}
|
--memory {{ template_memory }}
|
||||||
--core {{ template_cores }}
|
--core {{ template_cores }}
|
||||||
--net0 virtio,bridge=vmbr0
|
--net0 virtio,bridge=vlan66
|
||||||
--scsihw virtio-scsi-pci
|
--scsihw virtio-scsi-pci
|
||||||
--bios ovmf
|
--bios ovmf
|
||||||
--machine q35
|
--machine q35
|
||||||
@@ -98,9 +98,6 @@
|
|||||||
- name: Set boot order to the primary disk
|
- name: Set boot order to the primary disk
|
||||||
ansible.builtin.command: qm set {{ template_vmid }} --boot order=scsi0
|
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
|
- name: Convert the VM to a template
|
||||||
ansible.builtin.command: qm template {{ template_vmid }}
|
ansible.builtin.command: qm template {{ template_vmid }}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,192 @@
|
|||||||
|
---
|
||||||
|
- name: Clone and start one cloud-init VM
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
gather_facts: false
|
||||||
|
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 }}"
|
||||||
|
api_port: "{{ proxmox_api_port | default(8006) }}"
|
||||||
|
api_user: "{{ proxmox_api_token_id.split('!')[0] }}"
|
||||||
|
api_token_id: "{{ proxmox_api_token_id.split('!')[1] }}"
|
||||||
|
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||||
|
validate_certs: true
|
||||||
|
tasks:
|
||||||
|
- name: Validate hostname and DNS mapping 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.
|
||||||
|
|
||||||
|
- name: Look up requested hostname across the cluster
|
||||||
|
community.proxmox.proxmox_vm_info:
|
||||||
|
name: "{{ vm_hostname }}"
|
||||||
|
register: named_vm
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Reject an already used hostname
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: named_vm.proxmox_vms | length == 0
|
||||||
|
fail_msg: "Hostname {{ vm_hostname }} already exists; no VM was modified. Inspect it before retrying."
|
||||||
|
|
||||||
|
- name: Look up source template and its current configuration
|
||||||
|
community.proxmox.proxmox_vm_info:
|
||||||
|
vmid: "{{ vm_template_id }}"
|
||||||
|
type: qemu
|
||||||
|
config: current
|
||||||
|
register: source_vm
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Require a cloud-init-ready template on its current node
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- source_vm.proxmox_vms | length == 1
|
||||||
|
- source_vm.proxmox_vms[0].node is defined
|
||||||
|
- 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."
|
||||||
|
|
||||||
|
- name: Clone template into a new VM
|
||||||
|
community.proxmox.proxmox_kvm:
|
||||||
|
clone: source-template
|
||||||
|
vmid: "{{ vm_template_id }}"
|
||||||
|
name: "{{ vm_hostname }}"
|
||||||
|
node: "{{ source_vm.proxmox_vms[0].node }}"
|
||||||
|
storage: "{{ vm_storage }}"
|
||||||
|
full: true
|
||||||
|
state: present
|
||||||
|
register: cloned_vm
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Stop if cloning did not allocate a new VMID
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- cloned_vm.changed
|
||||||
|
- cloned_vm.vmid is defined
|
||||||
|
- cloned_vm.vmid | int != vm_template_id | int
|
||||||
|
fail_msg: >-
|
||||||
|
Clone did not return a valid new VMID (possibly allocated concurrently);
|
||||||
|
no configuration was attempted. Inspect the cluster before retrying.
|
||||||
|
|
||||||
|
- name: Configure VM before first boot
|
||||||
|
community.proxmox.proxmox_kvm:
|
||||||
|
vmid: "{{ cloned_vm.vmid }}"
|
||||||
|
node: "{{ source_vm.proxmox_vms[0].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 }}"
|
||||||
|
ipconfig:
|
||||||
|
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
|
||||||
|
community.proxmox.proxmox_disk:
|
||||||
|
vmid: "{{ cloned_vm.vmid }}"
|
||||||
|
disk: scsi0
|
||||||
|
size: "{{ vm_disk_gib }}G"
|
||||||
|
state: resized
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Start 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
|
||||||
|
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."
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
collections:
|
||||||
|
- name: community.proxmox
|
||||||
|
version: "2.0.0"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
server:
|
server:
|
||||||
image: gitea/gitea:1.27
|
image: gitea/gitea:28
|
||||||
container_name: gitea_server
|
container_name: gitea_server
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
homeassistant:
|
homeassistant:
|
||||||
image: homeassistant/home-assistant:2026.9
|
image: homeassistant/home-assistant:2026.10
|
||||||
container_name: homeassistant_core
|
container_name: homeassistant_core
|
||||||
hostname: homeassistant_core
|
hostname: homeassistant_core
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
proxmoxer>=2.3
|
proxmoxer>=2.3,<3
|
||||||
|
requests>=2.31,<3
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
network_application:
|
network_application:
|
||||||
image: lscr.io/linuxserver/unifi-network-application:10.6.101-ls143
|
image: lscr.io/linuxserver/unifi-network-application:10.6.109-ls152
|
||||||
container_name: unifi_network_application
|
container_name: unifi_network_application
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ variable "vm_user_sshkeys" {
|
|||||||
type = list(string)
|
type = list(string)
|
||||||
default = [
|
default = [
|
||||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID62LmYRu1rDUha3timAIcA39LtcIOny1iAgFLnxoBxm vez@bastion",
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID62LmYRu1rDUha3timAIcA39LtcIOny1iAgFLnxoBxm vez@bastion",
|
||||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHovfHKpqTvwj5zrcSuSZALa8iiH6qBvE5dyJCz9eQ2k vez@surface"
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHovfHKpqTvwj5zrcSuSZALa8iiH6qBvE5dyJCz9eQ2k vez@surface",
|
||||||
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG9bx04oxnZTmMm/7U9lUlhZM64xIMUSx48JiwxUH86x semaphore"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user