Better version

master
guppy 2023-04-30 15:14:06 +02:00
parent 4296543d12
commit 5cc121984b
5 changed files with 74 additions and 18 deletions

View File

@ -0,0 +1,14 @@
#!/bin/bash
#
# Script to generate a cloud-config file with a custom user and the script user SSH public key as authorized key
#
cat << EOF > cloud-init-conf.yml
#cloud-config
users:
- name: ansuser
ssh-authorized-keys:
- $(cat ~/.ssh/id_rsa.pub)
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
EOF

View File

@ -1,9 +0,0 @@
#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

@ -10,7 +10,7 @@
template_id: 1001
template_name: debian-11-cloudinit-template
template_memory: 4096
template_bridge: vmbr0
template_bridge: vmbr100
tasks:
- name: destroy template
command: "qm destroy {{ vm.template_id }}"
@ -23,6 +23,17 @@
dest: "{{ vm.cloud_image_path }}"
mode: 0700
- name: Install Cloud-init
apt:
name:
- cloud-init
- libguestfs-tools
become: yes
- name: Install QEMU agent on img
command: "virt-customize -a {{ vm.cloud_image_path }} --install qemu-guest-agent"
become: yes
- name : Copy cloud-init-config file
copy:
src: cloud-init-conf.yml
@ -54,6 +65,10 @@
command: "qm set {{ vm.template_id }} --serial0 socket --vga serial0"
become: yes
- name: enable qemu agent
command: "qm set {{ vm.template_id }} --agent 1"
become: yes
- name: add cloud-init-config
command: 'qm set {{ vm.template_id }} --cicustom "user=local:snippets/cloud-init-conf.yml"'
become: yes

View File

@ -12,22 +12,24 @@ resource "proxmox_vm_qemu" "control_plane" {
memory = 2048
scsihw = "virtio-scsi-pci"
bootdisk = "scsi0"
agent = 1
disk {
size = "20G"
type = "scsi"
storage = "local-lvm"
iothread = 1
iothread = 0
}
network {
model = "virtio"
bridge = "vmbr0"
bridge = "${var.vm_vmbr}"
tag = "${var.vm_vlan}"
}
# cloud-init settings
# adjust the ip and gateway addresses as needed
ipconfig0 = "ip=192.168.1.1${count.index}/24,gw=192.168.1.254"
ipconfig0 = "ip=${var.vm_plane_control_network}${count.index}/24,gw=${var.vm_gateway}"
}
resource "proxmox_vm_qemu" "worker_nodes" {
@ -44,20 +46,35 @@ resource "proxmox_vm_qemu" "worker_nodes" {
memory = 2048
scsihw = "virtio-scsi-pci"
bootdisk = "scsi0"
agent = 1
disk {
size = "20G"
type = "scsi"
storage = "local-lvm"
iothread = 1
iothread = 0
}
network {
model = "virtio"
bridge = "vmbr0"
bridge = "${var.vm_vmbr}"
tag = "${var.vm_vlan}"
}
# cloud-init settings
# adjust the ip and gateway addresses as needed
ipconfig0 = "ip=192.168.1.2${count.index}/24,gw=192.168.1.254"
ipconfig0 = "ip=${var.vm_worker_nodes_network}${count.index}/24,gw=${var.vm_gateway}"
}
# Generate inventory file
resource "local_file" "inventory" {
filename = "hosts.ini"
content = <<EOF
[control-plane]
${proxmox_vm_qemu.control_plane[0].default_ipv4_address}
[worker-node]
${proxmox_vm_qemu.worker_nodes[0].default_ipv4_address}
${proxmox_vm_qemu.worker_nodes[1].default_ipv4_address}
${proxmox_vm_qemu.worker_nodes[2].default_ipv4_address}
EOF
}

View File

@ -14,6 +14,25 @@ variable "pm_password" {
default = ""
}
variable "ssh_key_file" {
default = "~/.ssh/id_rsa.pub"
variable "vm_vmbr" {
default = "vmbr100"
}
# Use "-1" to disable VLAN
variable "vm_vlan" {
default = "300"
}
variable "vm_gateway" {
default = "192.168.230.254"
}
# The IP will be X.X.X.X${count.index}
variable "vm_plane_control_network" {
default = "192.168.230.1"
}
# The IP will be X.X.X.X${count.index}
variable "vm_worker_nodes_network" {
default = "192.168.230.2"
}