From 4059be838d43183510aa1f80ee7ff672fdf16aa6 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Fri, 26 Apr 2024 00:10:48 +0200 Subject: [PATCH] Aggiornato template con ultime impostazioni e test. --- pvm-ansible/Pulumi.yaml | 5 +++++ pvm-ansible/README.md | 3 +++ pvm-ansible/__main__.py | 41 +++++++++++++++++------------------- pvm-ansible/input.yaml | 1 + pvm-ansible/requirements.txt | 1 + 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/pvm-ansible/Pulumi.yaml b/pvm-ansible/Pulumi.yaml index 63e4d47..6bce2c2 100644 --- a/pvm-ansible/Pulumi.yaml +++ b/pvm-ansible/Pulumi.yaml @@ -2,5 +2,10 @@ name: ${PROJECT} description: ${DESCRIPTION} runtime: python + template: description: ProxmoxVE provider, Ansible powered with Python + config: + password: + description: Password of the root user over PVE. + secret: true diff --git a/pvm-ansible/README.md b/pvm-ansible/README.md index 64d82d0..a614236 100644 --- a/pvm-ansible/README.md +++ b/pvm-ansible/README.md @@ -1,3 +1,6 @@ +[![Deploy with Pulumi](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new?template=https://git.sys42.eu/syntaxerrormmm/pulumi-templates/src/branch/main/pvm-ansible) + + # Quick configuration # Check out the file `input.yml` for a quick setup for a new machine. diff --git a/pvm-ansible/__main__.py b/pvm-ansible/__main__.py index 0249be8..5396344 100644 --- a/pvm-ansible/__main__.py +++ b/pvm-ansible/__main__.py @@ -4,29 +4,28 @@ import pulumi import pulumi_proxmoxve as proxmox import pulumi_command as command import yaml +from dotmap import DotMap # Import configuration parameters from input.yaml -i = open("./input.yaml") -input_ = yaml.safe_load(i.read()) -i.close() +input_ = DotMap(yaml.safe_load(open("./input.yaml", "r").read())) # Check pulumi configuration config = pulumi.Config() provider = proxmox.Provider("proxmoxve", - endpoint=input_['pve']['url'], - insecure=input_['pve']['insecure'], - username=input_['pve']['username'], + endpoint=input_.pve.url, + insecure=input_.pve.insecure, + username=input_.pve.username, password=config.require_secret("password") ) -vm_name = input_['vm']['name'] -vm_username = input_['vm']['username'] -ansible_playbook = input_['ansible_playbook'] +vm_name = input_.vm.name +vm_username = input_.vm.username +ansible_playbook = input_.ansible_playbook vm = proxmox.vm.VirtualMachine("vm", name = vm_name, - node_name = input_['pve']['nodename'], + node_name = input_.pve.nodename, agent = proxmox.vm.VirtualMachineAgentArgs( enabled = True, trim = True, @@ -34,22 +33,20 @@ vm = proxmox.vm.VirtualMachine("vm", ), bios = "seabios", cpu = proxmox.vm.VirtualMachineCpuArgs( - cores = input_['vm']['cores'], - sockets = input_['vm']['sockets'] - ), - memory = proxmox.vm.VirtualMachineMemoryArgs( - dedicated = input_['vm']['ram'] + cores = input_.vm.cores, + sockets = input_.vm.sockets ), + memory = proxmox.vm.VirtualMachineMemoryArgs(dedicated = input_.vm.ram), clone = proxmox.vm.VirtualMachineCloneArgs( - node_name = input_['pve']['nodename'], - vm_id = input_['vm']['clone'], + node_name = input_.pve.nodename, + vm_id = input_.vm.clone, full = True ), disks = [ proxmox.vm.VirtualMachineDiskArgs( interface = "virtio0", - datastore_id = input_['pve']['storage'], - size = input_['vm']['disksize'], + datastore_id = input_.pve.storage, + size = input_.vm.disksize, file_format = "raw" ) ], @@ -65,11 +62,11 @@ vm = proxmox.vm.VirtualMachine("vm", ), initialization = proxmox.vm.VirtualMachineInitializationArgs( type = "nocloud", - datastore_id = input_['pve']['storage'], + datastore_id = input_.pve.storage, user_account = proxmox.vm.VirtualMachineInitializationUserAccountArgs( username = vm_username, - password = input_['vm']['password'], - keys = input_['vm']['sshkeys'] + password = input_.vm.password, + keys = input_.vm.sshkeys ) ), opts = pulumi.ResourceOptions( diff --git a/pvm-ansible/input.yaml b/pvm-ansible/input.yaml index 31e8b15..f2c7ab5 100644 --- a/pvm-ansible/input.yaml +++ b/pvm-ansible/input.yaml @@ -20,6 +20,7 @@ vm: - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILH5q/ObtC4VhNT88gebezP/svpvCoQLoZCh4DvUn4xq syntaxerrormmm@taz" + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGdTHkPCPUhvrcGgU9M6/BaEeirStM/kBnFxsLyXyelt syntaxerrormmm@kurotsuchi" # Ansible configuration ansible_playbook: deploy.yml diff --git a/pvm-ansible/requirements.txt b/pvm-ansible/requirements.txt index 729741d..e872837 100644 --- a/pvm-ansible/requirements.txt +++ b/pvm-ansible/requirements.txt @@ -1,3 +1,4 @@ pulumi>=3.0.0,<4.0.0 pulumi-proxmoxve>=2.0.0 pulumi-command>=0.4.1 +dotmap>=1.3.30