Renaming projects for quick retrieval.
This commit is contained in:
parent
9b8c772615
commit
fbf68c67b9
43 changed files with 112 additions and 1 deletions
2
vm-ansible/.gitignore
vendored
Normal file
2
vm-ansible/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.pyc
|
||||
venv/
|
5
vm-ansible/Pulumi.yaml
Normal file
5
vm-ansible/Pulumi.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
name: ${PROJECT}
|
||||
description: ${DESCRIPTION}
|
||||
runtime: python
|
||||
template:
|
||||
description: A Pulumi deployment with libvirt and Python
|
7
vm-ansible/README.md
Normal file
7
vm-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 libvirt:uri --plaintext "qemu:///system"
|
85
vm-ansible/__main__.py
Normal file
85
vm-ansible/__main__.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
"""A Pulumi-based infrastructure with libvirt and Python"""
|
||||
|
||||
import pulumi
|
||||
import pulumi_libvirt as lv
|
||||
import pulumi_command as command
|
||||
import yaml
|
||||
from dotmap import DotMap
|
||||
from jinja2 import Template
|
||||
from passlib.hash import sha512_crypt
|
||||
|
||||
conf = DotMap(yaml.safe_load(open("./input.yaml", "r").read()))
|
||||
cloudimages = DotMap(yaml.safe_load(open('cloud-images.yaml').read()))
|
||||
|
||||
# Replacing readed password with its own counterpart.
|
||||
conf.password = sha512_crypt.hash(conf.password, rounds=4096)
|
||||
|
||||
config = pulumi.Config()
|
||||
|
||||
pool = lv.Pool("pool",
|
||||
type = "dir",
|
||||
path = conf.poolpath
|
||||
)
|
||||
|
||||
baseimg = lv.Volume("base-image",
|
||||
pool = pool.name,
|
||||
source = cloudimages[conf.image]
|
||||
#source = "https://cdimage.debian.org/images/cloud/bullseye-backports/20220711-1073/debian-11-backports-generic-amd64-20220711-1073.qcow2"
|
||||
)
|
||||
|
||||
volume = lv.Volume("disk",
|
||||
base_volume_id = baseimg.id,
|
||||
pool = pool.name,
|
||||
size = int(conf.disksize) * 1024 ** 3
|
||||
)
|
||||
|
||||
# Stream configuration files
|
||||
userdata = Template(open("./cloud-init/user-data.jinja", "r").read()).render(conf)
|
||||
metadata = Template(open("./cloud-init/meta-data.jinja", "r").read()).render(conf)
|
||||
networkconfig = open("./cloud-init/network-config", "r").read()
|
||||
|
||||
cloudinit = lv.CloudInitDisk("cloud-init",
|
||||
meta_data = metadata,
|
||||
user_data = userdata,
|
||||
network_config = networkconfig
|
||||
)
|
||||
|
||||
vm = lv.Domain(conf.name,
|
||||
boot_devices = [ lv.DomainBootDeviceArgs(
|
||||
devs = [ "hd", "cdrom" ]
|
||||
) ],
|
||||
cloudinit = cloudinit.id,
|
||||
vcpu = conf.vcpu,
|
||||
disks = [ lv.DomainDiskArgs(volume_id = volume.id) ],
|
||||
memory = int(conf.ram),
|
||||
network_interfaces = [ lv.DomainNetworkInterfaceArgs(
|
||||
network_name = "default",
|
||||
wait_for_lease = True
|
||||
) ],
|
||||
consoles = [ lv.DomainConsoleArgs(
|
||||
type = "pty",
|
||||
target_port = 0,
|
||||
target_type = "serial"
|
||||
) ],
|
||||
opts = pulumi.ResourceOptions(
|
||||
custom_timeouts = pulumi.CustomTimeouts(create = "3m")
|
||||
)
|
||||
)
|
||||
|
||||
# Creating the inventory file
|
||||
inventory = command.local.Command("a-inventory",
|
||||
create = vm.network_interfaces[0]['addresses'][0].apply(
|
||||
lambda ipaddr: f"echo '{conf.name} ansible_host={ipaddr} ansible_user={conf.username}' >./inventory"
|
||||
),
|
||||
delete = "rm -f ./inventory",
|
||||
opts = pulumi.ResourceOptions(depends_on = [ vm ])
|
||||
)
|
||||
|
||||
# Applying the command
|
||||
execute_ansible = command.local.Command("a-deploy",
|
||||
create = f"ansible-playbook {conf.ansible_playbook}",
|
||||
delete = "rm -f ./ansible.log",
|
||||
opts = pulumi.ResourceOptions(depends_on = [ inventory ])
|
||||
)
|
||||
|
||||
pulumi.export("ip", vm.network_interfaces[0]['addresses'][0])
|
6
vm-ansible/ansible.cfg
Normal file
6
vm-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
|
3
vm-ansible/cloud-images.yaml
Normal file
3
vm-ansible/cloud-images.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
buster: https://cloud.debian.org/images/cloud/buster-backports/latest/debian-10-backports-generic-amd64.qcow2
|
||||
bullseye: https://cloud.debian.org/images/cloud/bullseye-backports/latest/debian-11-backports-generic-amd64.qcow2
|
||||
bookworm: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
|
2
vm-ansible/cloud-init/meta-data.jinja
Normal file
2
vm-ansible/cloud-init/meta-data.jinja
Normal file
|
@ -0,0 +1,2 @@
|
|||
instance-id: {{ name }}
|
||||
local-hostname: {{ name }}
|
5
vm-ansible/cloud-init/network-config
Normal file
5
vm-ansible/cloud-init/network-config
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
version: 2
|
||||
ethernets:
|
||||
ens3:
|
||||
dhcp4: true
|
24
vm-ansible/cloud-init/user-data.jinja
Normal file
24
vm-ansible/cloud-init/user-data.jinja
Normal file
|
@ -0,0 +1,24 @@
|
|||
#cloud-config
|
||||
resize_rootfs: true
|
||||
users:
|
||||
- name: {{ username }}
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
groups: users, admin
|
||||
shell: /bin/bash
|
||||
ssh_authorized_keys:
|
||||
{% for key in sshkeys %}
|
||||
- "{{ key }}"
|
||||
{% endfor %}
|
||||
hashed_passwd: {{ password }}
|
||||
ssh_pwauth: true
|
||||
disable_root: false
|
||||
chpasswd:
|
||||
expire: false
|
||||
list: |
|
||||
root:{{ password }}
|
||||
syntaxerrormmm:{{ password }}
|
||||
#packages:
|
||||
# - qemu-guest-agent
|
||||
#power_state:
|
||||
# delay: now
|
||||
# mode: reboot
|
6
vm-ansible/deploy.yml
Normal file
6
vm-ansible/deploy.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- hosts: all
|
||||
roles:
|
||||
- base_personal
|
||||
become: yes
|
||||
become_user: root
|
18
vm-ansible/input.yaml
Normal file
18
vm-ansible/input.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
# Basic VM configuration
|
||||
name: virtual-machine
|
||||
vcpu: 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"
|
||||
|
||||
image: bookworm
|
||||
poolpath: /var/tmp/libvirt/pulumi
|
||||
|
||||
# Ansible configuration
|
||||
ansible_playbook: deploy.yml
|
8
vm-ansible/requirements.txt
Normal file
8
vm-ansible/requirements.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
pyyaml>=6.0
|
||||
dotmap>=1.3.30
|
||||
protobuf==3.20.1
|
||||
pulumi>=3.0.0,<4.0.0
|
||||
pulumi_libvirt>=0.3.0
|
||||
pulumi-command>=0.4.1
|
||||
Jinja2>=3.1.2
|
||||
passlib>=1.7.4
|
Loading…
Add table
Add a link
Reference in a new issue