aboutsummaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
Diffstat (limited to 'roles')
-rw-r--r--roles/proxmox_instance/README.md87
-rw-r--r--roles/proxmox_instance/defaults/main.yml8
-rw-r--r--roles/proxmox_instance/tasks/main.yml8
3 files changed, 95 insertions, 8 deletions
diff --git a/roles/proxmox_instance/README.md b/roles/proxmox_instance/README.md
new file mode 100644
index 0000000..78fb350
--- /dev/null
+++ b/roles/proxmox_instance/README.md
@@ -0,0 +1,87 @@
+Proxmox Instance
+================
+
+Description
+-----------
+
+The `proxmox_instance` role creates a new Proxmox virtual machine.
+
+Each new virtual machine is cloned from the specified template VM, and
+cloud-init properties are set to ensure static IP configuration and SSH keys are
+set during the initial boot.
+
+This role uses the [proxmox\_kvm](https://docs.ansible.com/ansible/latest/collections/community/general/proxmox_kvm_module.html)
+module to create the virtual machines. Unfortunately, this module is pretty
+limited--it's unable to modify disk or NIC configuration after the VM is cloned.
+Therefore, we run some shell commands on the hypervisor to grow the disk, set
+the VLAN tag, etc.
+
+Note that this role uses `delegate_to` to run all tasks on the Proxmox server
+itself. As a result, you can actually run it against a VM that doesn't yet
+exist! This is how the [common](../common/) role creates VMs on-the-fly when
+configuring a host for the first time.
+
+
+Variables
+---------
+
+This role **accepts** the following variables:
+
+Variable | Default | Description
+-----------------------|--------------------------------|------------
+`proxmox_hostname` | `{{ inventory_hostname }}` | VM name
+`proxmox_onboot` | yes | Start VM automatically
+`proxmox_bridge` | `vmbr0` | Bridged virtual interface name
+`proxmox_firewall` | no | Enable Proxmox firewall
+`proxmox_storage` | `local-zfs` | Proxmox storage name
+`proxmox_disk` | 32 | Size of virtual disk (GB)
+`proxmox_memory` | 4096 | RAM (MB)
+`proxmox_cpu` | `host` | Virtual CPU model
+`proxmox_sockets` | 1 | Virtual CPU sockets
+`proxmox_cores` | 2 | Cores per socket
+`proxmox_bios` | `ovmf` | either `ovmf` or `seabios`
+`proxmox_template` | `rocky9.1` | Template VM name
+`proxmox_vlan` | `{{ vlan.id }}` | Virtual NIC VLAN tag
+`proxmox_ssd` | yes | Emulate an SSD
+`proxmox_discard` | yes | Enable TRIM commands from guest
+`proxmox_vga` | `serial0` | Virtual console device
+`proxmox_scsihw` | `virtio-scsi-pci` | Virtual SCSI device
+`proxmox_guest_agent` | yes | Guest uses `qemu-guest-agent`
+`proxmox_username` | `root` | Cloud-init username
+`proxmox_password` | `{{ root_password }}` | Cloud-init password
+`proxmox_pubkeys` | `{{ root_authorized_keys }}` | Cloud-init SSH public keys
+`proxmox_ip` | `{{ ip }}` | Cloud-init IP address
+`proxmox_gateway` | `{{ vlan.gateway }}` | Cloud-init default gateway
+`proxmox_netmask` | `{{ vlan }}` prefix | Cloud-init network prefix
+`proxmox_nameservers` | `{{ vlan.dns_servers }}` | Cloud-init DNS servers
+`proxmox_searchdomain` | `{{ domain }}` | Cloud-init DNS search domain
+`proxmox_userdata` | `local:snippets/userdata.yaml` | Cloud-init userdata file
+
+
+Usage
+-----
+
+Example playbook:
+
+````yaml
+- name: create proxmox VM
+ hosts: coolvm1
+ roles:
+ - role: proxmox_instance
+ vars:
+ proxmox_hostname: coolvm1
+ proxmox_disk: 64
+ proxmox_memory: 2048
+ proxmox_cores: 4
+ proxmox_template: rocky9.1
+ proxmox_vlan: 101
+ proxmox_username: root
+ proxmox_password: r00tp@ssw0rd
+ proxmox_ip: 10.10.10.99
+ proxmox_gateway: 10.10.10.1
+ proxmox_netmask: 24
+ proxmox_nameservers:
+ - 10.10.10.2
+ - 10.10.10.3
+ proxmox_searchdomain: example.com
+```
diff --git a/roles/proxmox_instance/defaults/main.yml b/roles/proxmox_instance/defaults/main.yml
index 5af0126..65842a3 100644
--- a/roles/proxmox_instance/defaults/main.yml
+++ b/roles/proxmox_instance/defaults/main.yml
@@ -24,8 +24,8 @@ proxmox_searchdomain: '{{ domain }}'
proxmox_discard: yes
proxmox_ssd: yes
-proxmox_kvm_vga: serial0
-proxmox_kvm_ciuser: root
-proxmox_kvm_scsihw: virtio-scsi-pci
-proxmox_kvm_guest_agent: yes
+proxmox_vga: serial0
+proxmox_username: root
+proxmox_scsihw: virtio-scsi-pci
+proxmox_guest_agent: yes
proxmox_userdata: local:snippets/userdata.yaml
diff --git a/roles/proxmox_instance/tasks/main.yml b/roles/proxmox_instance/tasks/main.yml
index 91959bf..da6712d 100644
--- a/roles/proxmox_instance/tasks/main.yml
+++ b/roles/proxmox_instance/tasks/main.yml
@@ -41,7 +41,7 @@
pre_enrolled_keys: 1
format: unspecified
name: '{{ proxmox_hostname }}'
- agent: '{{ proxmox_kvm_guest_agent }}'
+ agent: '{{ proxmox_guest_agent }}'
storage: '{{ proxmox_storage }}'
onboot: '{{ proxmox_onboot }}'
cpu: '{{ proxmox_cpu }}'
@@ -49,12 +49,12 @@
cores: '{{ proxmox_cores }}'
vcpus: '{{ proxmox_sockets * proxmox_cores }}'
memory: '{{ proxmox_memory }}'
- vga: '{{ proxmox_kvm_vga }}'
- scsihw: '{{ proxmox_kvm_scsihw }}'
+ vga: '{{ proxmox_vga }}'
+ scsihw: '{{ proxmox_scsihw }}'
nameservers: "{{ proxmox_nameservers | join(',') }}"
searchdomains: '{{ proxmox_searchdomain }}'
sshkeys: "{{ proxmox_pubkeys | join('\n') }}"
- ciuser: '{{ proxmox_kvm_ciuser }}'
+ ciuser: '{{ proxmox_username }}'
cipassword: '{{ proxmox_password }}'
cicustom: 'user={{ proxmox_userdata }}'
ipconfig: