Cambio nomi per template.

This commit is contained in:
Emiliano Vavassori 2022-08-21 00:55:12 +02:00
parent d5779c819d
commit b216e3361e
12 changed files with 0 additions and 0 deletions

4
pve-vm-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,7 @@
# Quick configuration #
Check out the file `input.yml` for a quick setup for a new machine.
Also, don't forget to setup the password for your account on your ProxmoxVE
server configuring `pulumi`:
$ pulumi config set password --secret <yourpassword>

View file

@ -0,0 +1,105 @@
"""ProxmoxVE provider, Ansible powered with Python"""
import pulumi
import pulumi_proxmoxve as proxmox
import pulumi_command as command
import yaml
# Import configuration parameters from input.yaml
i = open("./input.yaml")
input_ = yaml.safe_load(i.read())
i.close()
# Check pulumi configuration
config = pulumi.Config()
provider = proxmox.Provider("proxmoxve",
virtual_environment = {
"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 = proxmox.vm.VirtualMachine("vm",
name = vm_name,
node_name = input_['pve']['nodename'],
agent = proxmox.vm.VirtualMachineAgentArgs(
enabled = True,
trim = True,
type = "virtio"
),
bios = "seabios",
cpu = proxmox.vm.VirtualMachineCpuArgs(
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'],
full = True
),
disks = [
proxmox.vm.VirtualMachineDiskArgs(
interface = "virtio0",
datastore_id = input_['pve']['storage'],
size = input_['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 = input_['pve']['storage'],
user_account = proxmox.vm.VirtualMachineInitializationUserAccountArgs(
username = vm_username,
password = input_['vm']['password'],
keys = input_['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
inventory = command.local.Command("a-inventory",
create = vm.ipv4_addresses[1][0].apply(
lambda ipaddr: f"echo '{vm_name} ansible_host={ipaddr} ansible_user={vm_username}' >./inventory"
),
delete = "rm -f ./inventory",
opts = pulumi.ResourceOptions(depends_on = [ vm ])
)
# Try the deployment with ansible
# Applying the command
execute_ansible = command.local.Command("a-deploy",
create = vm.ipv4_addresses[1][0].apply(
lambda ipaddr: f"ansible-playbook {ansible_playbook}"
),
delete = "rm -f ./ansible.log",
opts = pulumi.ResourceOptions(depends_on = [ inventory ])
)
# Outputs
pulumi.export("ip", vm.ipv4_addresses[1][0])

View file

@ -0,0 +1,6 @@
[defaults]
collections_on_ansible_version_mismatch = ignore
action_warnings = False
host_key_checking = False
inventory = inventory
log_path = ./ansible.log

View file

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

View file

@ -0,0 +1,25 @@
---
pve:
url: "https://pve.vavassori.lcl:8006"
insecure: true
username: root@pam
nodename: pve
storage: local-lvm
# Basic VM configuration
vm:
name: virtual-machine
clone: 802
sockets: 1
cores: 1
ram: 2048
disksize: 20
username: syntaxerrormmm
password: cicciopasticcio
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

View file

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