diff --git a/pvm-ansible/Pulumi.yaml b/pvm-ansible/Pulumi.yaml index 8ece092..e1dfef6 100644 --- a/pvm-ansible/Pulumi.yaml +++ b/pvm-ansible/Pulumi.yaml @@ -8,11 +8,11 @@ template: config: pveHostname: type: String - default: pve.vavassori.lcl + default: vhost.vavassori.lcl description: PVE hostname pveNodeName: type: String - default: pve + default: vhost description: Node of the Proxmox VE to which write the VM. pveVerifySSL: type: Number @@ -28,7 +28,7 @@ template: description: Authentication token value for PVE Node pveDefaultStorage: type: String - default: local-lvm + default: local-zfs description: Default storage in which put the VMs hostname: type: String diff --git a/pvm-ansible/__main__.py b/pvm-ansible/__main__.py index f9595d1..158f483 100644 --- a/pvm-ansible/__main__.py +++ b/pvm-ansible/__main__.py @@ -18,17 +18,18 @@ verify = True if config.get_int("pveVerifySSL") == 1 else False pvedefaultstorage = config.require("pveDefaultStorage") vm_name: str = config.require("hostname") vm_username: str = config.require("cloudUsername") +tokenvalue = config.require_secret("pveTokenValue") provider = proxmox.Provider(pvehostname, endpoint=pveURL, insecure=not verify, - api_token=config.require_secret("pveTokenValue").apply(lambda x: f"{username}!{tokenname}={x}") + api_token=tokenvalue.apply(lambda x: f"{username}!{tokenname}={x}") ) pve = PveWrapper(pvehostname, username=username, token_name=tokenname, - token_value=config.require_secret("pveTokenValue").apply(lambda v: f"{v}"), + token_value=tokenvalue.apply(lambda v: f"{v}"), nodename=pvenodename, verify_ssl=verify ) @@ -37,10 +38,10 @@ vm = proxmox.vm.VirtualMachine(vm_name, name = vm_name, node_name = pvenodename, agent = proxmox.vm.VirtualMachineAgentArgs( - enabled = True, - trim = True, - type = "virtio" - ), + enabled=True, + type="virtio", + timeout="2m", + ), cpu = proxmox.vm.VirtualMachineCpuArgs( cores = config.get_int("vmSockets"), sockets = config.get_int("vmCores") @@ -75,7 +76,8 @@ vm = proxmox.vm.VirtualMachine(vm_name, username = vm_username, password = config.require_secret("cloudPassword"), keys = additional_config.sshkeys - ) + ), + vendor_data_file_id = "cloud-init/qemu-guest-agent_deb.yml" ), opts = pulumi.ResourceOptions( provider = provider, @@ -83,27 +85,27 @@ vm = proxmox.vm.VirtualMachine(vm_name, ) ) -ipv4_addresses = vm.vm_id.apply(lambda vm_id: pve.ipv4_addresses(f"{vm_id}")) +ipv4_addresses = vm.id.apply(lambda id: pve.ipv4_addresses(f"{id}")) -## Creating the inventory file -#inventory = command.local.Command("a-inventory", -# create = vm.ipv4_addresses.apply(lambda ipaddr: -# f"echo '{vm_name} ansible_host={ipaddr[0]['ipv4_address']} ansible_user={vm_username}' >./inventory" -# ), -# delete = "rm -f ./inventory", -# opts = pulumi.ResourceOptions(depends_on = [ vm, ipv4_addresses ]) -#) -# -## Applying the command -#for playbook in additional_config.playbooks: -# shortname: str = playbook.split(".")[0] -# command.local.Command(f"ap-{shortname}", -# create = vm.ipv4_addresses.apply( -# lambda run: f"ansible-playbook {run[0]['ipv4_address']}" -# ), -# delete = "rm -f ./ansible.log", -# opts = pulumi.ResourceOptions(depends_on = [ inventory ]) -# ) +# Creating the inventory file +inventory = command.local.Command("a-inventory", + create = ipv4_addresses.apply(lambda ipaddr: + f"echo '{vm_name} ansible_host={ipaddr[0]['address']} ansible_user={vm_username}' >./inventory" + ), + delete = "rm -f ./inventory", + opts = pulumi.ResourceOptions(depends_on = [ vm, ipv4_addresses ]) +) + +# Applying the command +for playbook in additional_config.playbooks: + shortname: str = playbook.split(".")[0] + command.local.Command(f"ap-{shortname}", + create = vm.ipv4_addresses.apply( + lambda run: f"ansible-playbook {run[0]['ipv4_address']}" + ), + delete = "rm -f ./ansible.log", + opts = pulumi.ResourceOptions(depends_on = [ inventory ]) + ) # Outputs pulumi.export("ipv4_addresses", vm.ipv4_addresses) diff --git a/pvm-ansible/additional_config.py b/pvm-ansible/additional_config.py index 3114c89..10159fd 100644 --- a/pvm-ansible/additional_config.py +++ b/pvm-ansible/additional_config.py @@ -14,8 +14,12 @@ playbooks = [ ] os_to_template = { - "tpl-ci-debian12": 808, - "debian12": 808, - "bookworm": 808 + "tpl-ci-debian12": 901, + "debian12": 901, + "bookworm": 901, + "tpl-ci-ubuntu2404": 904, + "ubuntu2404": 904, + "tpl-ci-rocky9": 902, + "rocky9": 902 } diff --git a/pvm-ansible/cloud-init/qemu-guest-agent_deb.yml b/pvm-ansible/cloud-init/qemu-guest-agent_deb.yml new file mode 100644 index 0000000..92453cc --- /dev/null +++ b/pvm-ansible/cloud-init/qemu-guest-agent_deb.yml @@ -0,0 +1,5 @@ +#cloud-config +runcmd: + - apt update + - apt install -y qemu-guest-agent + - systemctl start qemu-guest-agent diff --git a/pvm-ansible/pvewrapper.py b/pvm-ansible/pvewrapper.py index 30ff008..e19d9da 100644 --- a/pvm-ansible/pvewrapper.py +++ b/pvm-ansible/pvewrapper.py @@ -7,7 +7,7 @@ import time class PveWrapper: - def __init__(self, hostname: str, username: str, token_name: str, token_value: str, nodename: str, verify_ssl=False) -> None: + def __init__(self, hostname, username, token_name, token_value, nodename, verify_ssl=False) -> None: """Wrapper for Proxmox API query.""" self.conn = ProxmoxAPI(