Tentativo di cambio per pvm-ansible.
This commit is contained in:
parent
b113990fda
commit
05af88acd9
@ -8,11 +8,11 @@ template:
|
|||||||
config:
|
config:
|
||||||
pveHostname:
|
pveHostname:
|
||||||
type: String
|
type: String
|
||||||
default: pve.vavassori.lcl
|
default: vhost.vavassori.lcl
|
||||||
description: PVE hostname
|
description: PVE hostname
|
||||||
pveNodeName:
|
pveNodeName:
|
||||||
type: String
|
type: String
|
||||||
default: pve
|
default: vhost
|
||||||
description: Node of the Proxmox VE to which write the VM.
|
description: Node of the Proxmox VE to which write the VM.
|
||||||
pveVerifySSL:
|
pveVerifySSL:
|
||||||
type: Number
|
type: Number
|
||||||
@ -28,7 +28,7 @@ template:
|
|||||||
description: Authentication token value for PVE Node
|
description: Authentication token value for PVE Node
|
||||||
pveDefaultStorage:
|
pveDefaultStorage:
|
||||||
type: String
|
type: String
|
||||||
default: local-lvm
|
default: local-zfs
|
||||||
description: Default storage in which put the VMs
|
description: Default storage in which put the VMs
|
||||||
hostname:
|
hostname:
|
||||||
type: String
|
type: String
|
||||||
|
@ -18,17 +18,18 @@ verify = True if config.get_int("pveVerifySSL") == 1 else False
|
|||||||
pvedefaultstorage = config.require("pveDefaultStorage")
|
pvedefaultstorage = config.require("pveDefaultStorage")
|
||||||
vm_name: str = config.require("hostname")
|
vm_name: str = config.require("hostname")
|
||||||
vm_username: str = config.require("cloudUsername")
|
vm_username: str = config.require("cloudUsername")
|
||||||
|
tokenvalue = config.require_secret("pveTokenValue")
|
||||||
|
|
||||||
provider = proxmox.Provider(pvehostname,
|
provider = proxmox.Provider(pvehostname,
|
||||||
endpoint=pveURL,
|
endpoint=pveURL,
|
||||||
insecure=not verify,
|
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,
|
pve = PveWrapper(pvehostname,
|
||||||
username=username,
|
username=username,
|
||||||
token_name=tokenname,
|
token_name=tokenname,
|
||||||
token_value=config.require_secret("pveTokenValue").apply(lambda v: f"{v}"),
|
token_value=tokenvalue.apply(lambda v: f"{v}"),
|
||||||
nodename=pvenodename,
|
nodename=pvenodename,
|
||||||
verify_ssl=verify
|
verify_ssl=verify
|
||||||
)
|
)
|
||||||
@ -37,10 +38,10 @@ vm = proxmox.vm.VirtualMachine(vm_name,
|
|||||||
name = vm_name,
|
name = vm_name,
|
||||||
node_name = pvenodename,
|
node_name = pvenodename,
|
||||||
agent = proxmox.vm.VirtualMachineAgentArgs(
|
agent = proxmox.vm.VirtualMachineAgentArgs(
|
||||||
enabled = True,
|
enabled=True,
|
||||||
trim = True,
|
type="virtio",
|
||||||
type = "virtio"
|
timeout="2m",
|
||||||
),
|
),
|
||||||
cpu = proxmox.vm.VirtualMachineCpuArgs(
|
cpu = proxmox.vm.VirtualMachineCpuArgs(
|
||||||
cores = config.get_int("vmSockets"),
|
cores = config.get_int("vmSockets"),
|
||||||
sockets = config.get_int("vmCores")
|
sockets = config.get_int("vmCores")
|
||||||
@ -75,7 +76,8 @@ vm = proxmox.vm.VirtualMachine(vm_name,
|
|||||||
username = vm_username,
|
username = vm_username,
|
||||||
password = config.require_secret("cloudPassword"),
|
password = config.require_secret("cloudPassword"),
|
||||||
keys = additional_config.sshkeys
|
keys = additional_config.sshkeys
|
||||||
)
|
),
|
||||||
|
vendor_data_file_id = "cloud-init/qemu-guest-agent_deb.yml"
|
||||||
),
|
),
|
||||||
opts = pulumi.ResourceOptions(
|
opts = pulumi.ResourceOptions(
|
||||||
provider = provider,
|
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
|
# Creating the inventory file
|
||||||
#inventory = command.local.Command("a-inventory",
|
inventory = command.local.Command("a-inventory",
|
||||||
# create = vm.ipv4_addresses.apply(lambda ipaddr:
|
create = ipv4_addresses.apply(lambda ipaddr:
|
||||||
# f"echo '{vm_name} ansible_host={ipaddr[0]['ipv4_address']} ansible_user={vm_username}' >./inventory"
|
f"echo '{vm_name} ansible_host={ipaddr[0]['address']} ansible_user={vm_username}' >./inventory"
|
||||||
# ),
|
),
|
||||||
# delete = "rm -f ./inventory",
|
delete = "rm -f ./inventory",
|
||||||
# opts = pulumi.ResourceOptions(depends_on = [ vm, ipv4_addresses ])
|
opts = pulumi.ResourceOptions(depends_on = [ vm, ipv4_addresses ])
|
||||||
#)
|
)
|
||||||
#
|
|
||||||
## Applying the command
|
# Applying the command
|
||||||
#for playbook in additional_config.playbooks:
|
for playbook in additional_config.playbooks:
|
||||||
# shortname: str = playbook.split(".")[0]
|
shortname: str = playbook.split(".")[0]
|
||||||
# command.local.Command(f"ap-{shortname}",
|
command.local.Command(f"ap-{shortname}",
|
||||||
# create = vm.ipv4_addresses.apply(
|
create = vm.ipv4_addresses.apply(
|
||||||
# lambda run: f"ansible-playbook {run[0]['ipv4_address']}"
|
lambda run: f"ansible-playbook {run[0]['ipv4_address']}"
|
||||||
# ),
|
),
|
||||||
# delete = "rm -f ./ansible.log",
|
delete = "rm -f ./ansible.log",
|
||||||
# opts = pulumi.ResourceOptions(depends_on = [ inventory ])
|
opts = pulumi.ResourceOptions(depends_on = [ inventory ])
|
||||||
# )
|
)
|
||||||
|
|
||||||
# Outputs
|
# Outputs
|
||||||
pulumi.export("ipv4_addresses", vm.ipv4_addresses)
|
pulumi.export("ipv4_addresses", vm.ipv4_addresses)
|
||||||
|
@ -14,8 +14,12 @@ playbooks = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
os_to_template = {
|
os_to_template = {
|
||||||
"tpl-ci-debian12": 808,
|
"tpl-ci-debian12": 901,
|
||||||
"debian12": 808,
|
"debian12": 901,
|
||||||
"bookworm": 808
|
"bookworm": 901,
|
||||||
|
"tpl-ci-ubuntu2404": 904,
|
||||||
|
"ubuntu2404": 904,
|
||||||
|
"tpl-ci-rocky9": 902,
|
||||||
|
"rocky9": 902
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
pvm-ansible/cloud-init/qemu-guest-agent_deb.yml
Normal file
5
pvm-ansible/cloud-init/qemu-guest-agent_deb.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#cloud-config
|
||||||
|
runcmd:
|
||||||
|
- apt update
|
||||||
|
- apt install -y qemu-guest-agent
|
||||||
|
- systemctl start qemu-guest-agent
|
@ -7,7 +7,7 @@ import time
|
|||||||
|
|
||||||
class PveWrapper:
|
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."""
|
"""Wrapper for Proxmox API query."""
|
||||||
|
|
||||||
self.conn = ProxmoxAPI(
|
self.conn = ProxmoxAPI(
|
||||||
|
Loading…
Reference in New Issue
Block a user