Add cloud-init-config support

master
guppy 2023-04-29 15:47:06 +02:00
parent 20a72b0ce9
commit 4296543d12
3 changed files with 28 additions and 5 deletions

View File

@ -0,0 +1,9 @@
#cloud-config
users:
- default
- name: ansuser
ssh-authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDeDXn6rKQ/E6ND36C9r+04DS78C3d9hpSzcvBbBvCZ7kPEUFVrV0MiLZbBCAaaunIFsQ9hfq2ZlrlDmYLWhaxdtS8VEckJiZarvQ32aLEwFBaW7NwF1i5qyHaz7pL1NPQKHbQ3s7pBrUKotD3yX1yZIXA9RyCCpru1sWxhDRROWgu20FGF6D6Mv3gw9qORdEnrmtqz4ovYVHj3MuzHRVGttDvhrAoXDa66dLrpYaYdLSAjQqtuW0TO+ZTH3YLE7thwmh/QdHuDSD1Bs1r5yYli/CiljyxD2H1Q+wcivYEuc4Pk/B06uKFo+9wLBWVHHTrzsforGY0FQiUO+dX5qZQMhPotL9BUDkJcUNBoUycyuuHnj+REtaMlJChLPXhXGY6l7uczNfOPXCj+AlbK9KTqeAdLH81pJgD0F2F+j+pBtHu5oxQzcAkD+k1t4c+ndWNMO+MADCUOmxFijDr+S3F1aIUL1ixovQ9w6+RxkuPzGCGKnPM/9z+yhZyvZplMk1Bd8oAOqMCZqAfTDzuVl1Te/xq6PoArJ5mtLBoATrFHRsg2J07tJf3USjFIzp20EZiEdePs/slQ8rqOuYqCDKlMXZY0YBObmtVOIMaWKHzqkmO59B+aFDbLgHvwdSaSoqvrTHD4E1F2G3Oz08bo+QK4//4zKdjn1TMKzzg/pQ/idQ== guppy@D11-TP
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash

View File

@ -1,7 +1,7 @@
---
- name: "create VM template"
hosts: pve
remote_user: metal
remote_user: ansuser
gather_facts: no
vars:
vm:
@ -12,12 +12,24 @@
template_memory: 4096
template_bridge: vmbr0
tasks:
- name: destroy template
command: "qm destroy {{ vm.template_id }}"
become: yes
ignore_errors: true
- name : download cloud image
get_url:
url: "{{ vm.cloud_image_url }}"
dest: "{{ vm.cloud_image_path }}"
mode: 0700
- name : Copy cloud-init-config file
copy:
src: cloud-init-conf.yml
dest: /var/lib/vz/snippets/cloud-init-conf.yml
mode: '0700'
become: yes
- name: create a VM to use as a template
command: "qm create {{ vm.template_id }} --name {{ vm.template_name }} --memory {{ vm.template_memory }} --net0 virtio,bridge={{ vm.template_bridge }}"
become: yes
@ -42,6 +54,10 @@
command: "qm set {{ vm.template_id }} --serial0 socket --vga serial0"
become: yes
- name: add cloud-init-config
command: 'qm set {{ vm.template_id }} --cicustom "user=local:snippets/cloud-init-conf.yml"'
become: yes
- name: create template
command: "qm template {{ vm.template_id }}"
become: yes

View File

@ -27,8 +27,7 @@ resource "proxmox_vm_qemu" "control_plane" {
# cloud-init settings
# adjust the ip and gateway addresses as needed
ipconfig0 = "ip=192.168.0.11${count.index}/24,gw=192.168.0.1"
sshkeys = file("${var.ssh_key_file}")
ipconfig0 = "ip=192.168.1.1${count.index}/24,gw=192.168.1.254"
}
resource "proxmox_vm_qemu" "worker_nodes" {
@ -60,6 +59,5 @@ resource "proxmox_vm_qemu" "worker_nodes" {
# cloud-init settings
# adjust the ip and gateway addresses as needed
ipconfig0 = "ip=192.168.0.12${count.index}/24,gw=192.168.0.1"
sshkeys = file("${var.ssh_key_file}")
ipconfig0 = "ip=192.168.1.2${count.index}/24,gw=192.168.1.254"
}