2022-08-17 21:34:26 +02:00
|
|
|
"""ProxmoxVE provider, Ansible powered with Python"""
|
|
|
|
|
|
|
|
import pulumi
|
|
|
|
import pulumi_proxmoxve as proxmox
|
|
|
|
import pulumi_command as command
|
|
|
|
|
|
|
|
# Basic PVE configuration
|
|
|
|
pve_url = "https://pve.vavassori.lcl:8006"
|
|
|
|
pve_username = "root@pam"
|
|
|
|
pve_nodename = "pve"
|
|
|
|
pve_storage = "local-lvm"
|
|
|
|
|
|
|
|
# Basic VM configuration
|
|
|
|
vm_name = "virtual-machine"
|
|
|
|
vm_clone = 802
|
|
|
|
vm_sockets = 1
|
|
|
|
vm_cores = 1
|
|
|
|
vm_ram = 2048
|
|
|
|
vm_disksize = 20
|
|
|
|
vm_username = "syntaxerrormmm"
|
|
|
|
vm_sshkeys = [
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso",
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps",
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo"
|
|
|
|
]
|
|
|
|
|
|
|
|
# Ansible configuration
|
|
|
|
ansible_playbook = "deploy.yml"
|
|
|
|
|
|
|
|
# Start of the program
|
|
|
|
|
|
|
|
config = pulumi.Config()
|
|
|
|
|
|
|
|
provider = proxmox.Provider("proxmoxve",
|
|
|
|
virtual_environment = {
|
|
|
|
"endpoint": pve_url,
|
|
|
|
"insecure": True,
|
|
|
|
"username": pve_username,
|
|
|
|
"password": config.require_secret("password")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
vm = proxmox.vm.VirtualMachine("vm",
|
|
|
|
name = vm_name,
|
|
|
|
node_name = pve_nodename,
|
|
|
|
agent = proxmox.vm.VirtualMachineAgentArgs(
|
|
|
|
enabled = True,
|
|
|
|
trim = True,
|
|
|
|
type = "virtio"
|
|
|
|
),
|
|
|
|
bios = "seabios",
|
|
|
|
cpu = proxmox.vm.VirtualMachineCpuArgs(
|
|
|
|
cores = vm_cores,
|
|
|
|
sockets = vm_sockets
|
|
|
|
),
|
|
|
|
memory = proxmox.vm.VirtualMachineMemoryArgs(
|
2022-08-17 21:42:12 +02:00
|
|
|
dedicated = vm_ram
|
2022-08-17 21:34:26 +02:00
|
|
|
),
|
|
|
|
clone = proxmox.vm.VirtualMachineCloneArgs(
|
|
|
|
node_name = pve_nodename,
|
|
|
|
vm_id = vm_clone,
|
|
|
|
full = True
|
|
|
|
),
|
|
|
|
disks = [
|
|
|
|
proxmox.vm.VirtualMachineDiskArgs(
|
|
|
|
interface = "virtio0",
|
|
|
|
datastore_id = pve_storage,
|
|
|
|
size = vm_disksize,
|
|
|
|
file_format = "raw"
|
|
|
|
)
|
|
|
|
],
|
|
|
|
network_devices = [
|
|
|
|
proxmox.vm.VirtualMachineNetworkDeviceArgs(
|
|
|
|
bridge = "vmbr0",
|
|
|
|
model = "virtio"
|
|
|
|
)
|
|
|
|
],
|
|
|
|
on_boot = True,
|
|
|
|
operating_system = proxmox.vm.VirtualMachineOperatingSystemArgs(
|
|
|
|
type = "l26"
|
|
|
|
),
|
|
|
|
initialization = proxmox.vm.VirtualMachineInitializationArgs(
|
|
|
|
type = "nocloud",
|
|
|
|
datastore_id = pve_storage,
|
|
|
|
user_account = proxmox.vm.VirtualMachineInitializationUserAccountArgs(
|
|
|
|
username = vm_username,
|
|
|
|
password = "cicciopasticcio",
|
|
|
|
keys = vm_sshkeys
|
|
|
|
)
|
|
|
|
),
|
|
|
|
opts = pulumi.ResourceOptions(
|
|
|
|
provider = provider
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# First item of the ipv4_addresses is of the loopback interface (so the usual 127.0.0.1). Let's get the second and grab only the text.
|
|
|
|
|
|
|
|
# Creating the inventory file.
|
|
|
|
with open('inventory', 'w') as f:
|
2022-08-17 21:55:14 +02:00
|
|
|
vm.ipv4_addresses[1][0].apply(
|
|
|
|
lambda lanip: f.write(f"{vm_name} ansible_host={lanip} ansible_user={vm_username}")
|
|
|
|
)
|
2022-08-17 21:34:26 +02:00
|
|
|
|
|
|
|
# Try the deployment with ansible
|
|
|
|
|
|
|
|
# Applying the command
|
|
|
|
execute_ansible = command.local.Command("ansible",
|
2022-08-17 21:42:12 +02:00
|
|
|
create = f"ansible-playbook {ansible_playbook}",
|
2022-08-17 21:47:29 +02:00
|
|
|
opts = pulumi.ResourceOptions(depends_on = [vm])
|
2022-08-17 21:34:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Outputs
|
2022-08-17 21:55:14 +02:00
|
|
|
pulumi.export("ip", vm.ipv4_addresses[1][0])
|