add ailab config

This commit is contained in:
TapTap committed 2026-11-13 10:59:09 +01:00
1 parent 471e4c99dc
commit 6069ab5ffa
7 files changed
+220

No files matched your search

+1
View File
@@ -21,6 +21,7 @@ override.tf.json
# Ignore transient lock info files created by terraform apply
.terraform.tfstate.lock.info
.terraform.lock.hcl
# Ignore CLI configuration files
.terraformrc
+9
View File
@@ -0,0 +1,9 @@
[defaults]
inventory = inventory.ini
host_key_checking = False
interpreter_python = auto_silent
stdout_callback = default
result_format = yaml
[ssh_connection]
pipelining = True
+16
View File
@@ -0,0 +1,16 @@
- name: Ailab Sandbox
hosts: all
gather_facts: false
pre_tasks:
- name: Wait for VM to finish booting and accept SSH
ansible.builtin.wait_for_connection:
timeout: 180
tasks:
- name: Install nix
ansible.builtin.shell: curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --daemon
args:
creates: /nix/var/nix/profiles/default/bin/nix
- name: Install opencode
ansible.builtin.shell: curl -fsSL https://opencode.ai/v2/install | bash
args:
creates: /home/taptap/.opencode/bin/opencode
+17
View File
@@ -0,0 +1,17 @@
#cloud-config
ssh_pwauth: true
users:
- name: ${username}
groups: [sudo]
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
plain_text_passwd: ${jsonencode(password)}
package_update: true
packages:
- qemu-guest-agent
runcmd:
- systemctl enable --now qemu-guest-agent
- sudo add-apt-repository -y ppa:jdxcode/mise
- sudo apt update
- sudo apt install -y mise
+130
View File
@@ -0,0 +1,130 @@
data "proxmox_virtual_environment_nodes" "nodes" {}
# data "proxmox_datastores" "datastores" {
# node_name = data.proxmox_virtual_environment_nodes.nodes.names[0]
# }
#
# output "datastores" {
# value = data.proxmox_datastores.datastores
# }
resource "proxmox_download_file" "ubuntu_cloud" {
content_type = "import"
datastore_id = var.datastore_id
node_name = var.node
url = "https://cloud-images.ubuntu.com/releases/resolute/release/ubuntu-26.04-server-cloudimg-amd64.img"
file_name = "ubuntu-26-04-server-cloudimg.qcow2"
}
resource "proxmox_virtual_environment_file" "qemu-startup" {
content_type = "snippets"
datastore_id = var.datastore_id
node_name = var.node
source_raw {
data = templatefile("${path.module}/cloud-inits/qemu.yaml.tftpl", { password = var.vm_password
username = var.vm_username })
file_name = "qemu-startup-config.yaml"
}
}
resource "proxmox_virtual_environment_vm" "ailab" {
name = "ailab"
description = "sandboxed playground for ai agents"
tags = ["ai", "ubuntu"]
node_name = var.node
keyboard_layout = "de"
bios = "ovmf"
machine = "q35"
scsi_hardware = "virtio-scsi-single"
operating_system {
type = "l26"
}
efi_disk {
datastore_id = var.datastore_id
type = "4m"
pre_enrolled_keys = false
}
disk {
datastore_id = var.datastore_id
import_from = proxmox_download_file.ubuntu_cloud.id
interface = "scsi0"
size = "64"
discard = "on"
iothread = true
ssd = true
}
initialization {
datastore_id = var.datastore_id
user_data_file_id = proxmox_virtual_environment_file.qemu-startup.id
ip_config {
ipv4 {
address = "dhcp"
}
}
}
agent {
enabled = true
}
serial_device {}
cpu {
cores = 2
type = "host"
}
memory {
dedicated = 8192
floating = 8192
}
network_device {
bridge = "vmbr2"
firewall = true
}
}
output "test" {
value = flatten([for ipv4 in proxmox_virtual_environment_vm.ailab.ipv4_addresses : ipv4 if !contains(ipv4, "127.0.0.1")])[0]
}
data "ansible_inventory" "ailab" {
group {
name = "sanboxes"
host {
name = flatten([for ipv4 in proxmox_virtual_environment_vm.ailab.ipv4_addresses : ipv4 if !contains(ipv4, "127.0.0.1")])[0]
ansible_user = var.vm_username
ansible_password = var.vm_password
}
}
}
action "ansible_playbook_run" "update_ailab" {
config {
playbooks = ["${path.module}/ansible/playbook.yaml"]
inventories = [data.ansible_inventory.ailab.json]
}
}
resource "terraform_data" "playbook_trigger" {
input = {
vm_id = proxmox_virtual_environment_vm.ailab.id
playbook_hash = filemd5("${path.module}/ansible/playbook.yaml")
}
lifecycle {
action_trigger {
events = [after_create, after_update]
actions = [action.ansible_playbook_run.update_ailab]
}
}
depends_on = [proxmox_virtual_environment_vm.ailab]
}
+19
View File
@@ -0,0 +1,19 @@
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "~> 0.122.0"
}
ansible = {
version = "~> 1.4.0"
source = "ansible/ansible"
}
}
}
provider "proxmox" {
endpoint = var.proxmox_url
username = var.proxmox_username
password = var.proxmox_password
insecure = true
}
+28
View File
@@ -0,0 +1,28 @@
variable "proxmox_url" {
type = string
}
variable "proxmox_username" {
type = string
}
variable "proxmox_password" {
type = string
sensitive = true
}
variable "vm_username" {
type = string
}
variable "vm_password" {
type = string
sensitive = true
}
variable "node" {
type = string
}
variable "datastore_id" {
type = string
}