Renaming projects for quick retrieval.
This commit is contained in:
parent
9b8c772615
commit
fbf68c67b9
43 changed files with 112 additions and 1 deletions
4
pvm-ansible/.gitignore
vendored
Normal file
4
pvm-ansible/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
*.pyc
|
||||
venv/
|
||||
Pulumi.*.yaml
|
||||
inventory
|
6
pvm-ansible/Pulumi.yaml
Normal file
6
pvm-ansible/Pulumi.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
name: ${PROJECT}
|
||||
description: ${DESCRIPTION}
|
||||
runtime: python
|
||||
template:
|
||||
description: ProxmoxVE provider, Ansible powered with Python
|
7
pvm-ansible/README.md
Normal file
7
pvm-ansible/README.md
Normal 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>
|
105
pvm-ansible/__main__.py
Normal file
105
pvm-ansible/__main__.py
Normal 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])
|
6
pvm-ansible/ansible.cfg
Normal file
6
pvm-ansible/ansible.cfg
Normal 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
|
6
pvm-ansible/deploy.yml
Normal file
6
pvm-ansible/deploy.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- hosts: all
|
||||
roles:
|
||||
- base_personal
|
||||
become: yes
|
||||
become_user: root
|
25
pvm-ansible/input.yaml
Normal file
25
pvm-ansible/input.yaml
Normal 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
|
3
pvm-ansible/requirements.txt
Normal file
3
pvm-ansible/requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
pulumi>=3.0.0,<4.0.0
|
||||
pulumi-proxmoxve>=2.0.0
|
||||
pulumi-command>=0.4.1
|
Loading…
Add table
Add a link
Reference in a new issue