Adding a new template.

This commit is contained in:
Emiliano Vavassori 2022-08-17 21:34:26 +02:00
parent 2c42526b20
commit 6b6795c218
7 changed files with 139 additions and 0 deletions

4
proxmoxve-ansible-python/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.pyc
venv/
Pulumi.*.yaml
inventory

View File

@ -0,0 +1,6 @@
---
name: ${PROJECT}
description: ${DESCRIPTION}
runtime: python
template:
description: ProxmoxVE provider, Ansible powered with Python

View File

@ -0,0 +1,3 @@
# Required configuration parameters #
- `password`: password of the `root@pam` user (use `--secret` please)

View File

@ -0,0 +1,112 @@
"""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(
dedicated = mv_ram
),
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
)
)
# Getting local IP
# 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.
lanip = vm.ipv4_addresses[1][0]
# Creating the inventory file.
with open('inventory', 'w') as f:
f.write(f"{vm_name} ansible_host={lanip} ansible_user={vm_username}")
# Try the deployment with ansible
# Applying the command
execute_ansible = command.local.Command("ansible",
create = f"ansible-playbook {ansible_playbook}"
)
# Outputs
pulumi.export("ip", lanip)

View File

@ -0,0 +1,5 @@
[defaults]
collections_on_ansible_version_mismatch = False
action_warnings = False
host_key_checking = False
inventory = inventory

View File

@ -0,0 +1,6 @@
---
- hosts: all
roles:
- base_personal
become: yes
become_user: root

View File

@ -0,0 +1,3 @@
pulumi>=3.0.0,<4.0.0
pulumi-proxmoxve>=2.0.0
pulumi-command>=0.4.1