Added libvirt-ansible-python template.

This commit is contained in:
Emiliano Vavassori 2022-08-20 00:45:47 +02:00
parent dd31b87720
commit 5ee69d1f94
10 changed files with 135 additions and 0 deletions

2
libvirt-ansible-python/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.pyc
venv/

View File

@ -0,0 +1,5 @@
name: ${PROJECT}
description: ${DESCRIPTION}
runtime: python
template:
description: A Pulumi deployment with libvirt and Python

View File

@ -0,0 +1,9 @@
# Quick configuration #
To quickly set up your pulumi deployment, configure the following settings:
$ pulumi config set libvirt:uri --plaintext "qemu:///system"
$ pulumi config set image_url --plaintext "https://cdimage.debian.org/images/cloud/bullseye-backports/20220711-1073/debian-11-backports-generic-amd64-20220711-1073.qcow2"
$ pulumi config set disksize --plaintext 20
$ pulumi config set memory --plaintext 2048

View File

@ -0,0 +1,74 @@
"""A Pulumi-based infrastructure with libvirt and Python"""
import pulumi
import pulumi_libvirt as lv
import pulumi_command as command
config = pulumi.Config()
pool = lv.Pool("default",
type = "dir",
path = "/var/tmp/libvirt/pulumi"
)
baseimg = lv.Volume("base-image",
pool = pool.name,
source = config.require("image_url")
#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(config.require("disksize")) * 1024 ** 3
)
# Stream configuration files
userdata = open("./cloud-init/user-data", "r").read()
metadata = open("./cloud-init/meta-data", "r").read()
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("debian11",
boot_devices = [ lv.DomainBootDeviceArgs(
devs = [ "hd", "cdrom" ]
) ],
cloudinit = cloudinit.id,
disks = [ lv.DomainDiskArgs(volume_id = volume.id) ],
memory = int(config.require("memory")),
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 '{vm_name} ansible_host={ipaddr} ansible_user=syntaxerrormm' >./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 {ansible_playbook}",
delete = "rm -f ./ansible.log",
opts = pulumi.ResourceOptions(depends_on = [ inventory ])
)
pulumi.export("ip", vm.network_interfaces[0]['addresses'][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,2 @@
instance-id: debian11
local-hostname: debian11

View File

@ -0,0 +1,4 @@
version: 2
ethernets:
interface0:
dhcp4: true

View File

@ -0,0 +1,24 @@
#cloud-config
resize_rootfs: true
users:
- name: syntaxerrormmm
sudo: ALL=(ALL) NOPASSWD:ALL
groups: users, admin
shell: /bin/bash
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo
hashed_passwd: $6$rounds=4096$4ZUeoch.EwyR/TLb$.71i1otUQpw2eMlrjcP3H4XxsnLlVbIQxagFDGviOvCaIz7ONa.tTZPO09YL7hiAh4vLaTcGD43VoAM6tEYjx/
ssh_pwauth: true
disable_root: false
chpasswd:
expire: false
list: |
root:$6$rounds=4096$4ZUeoch.EwyR/TLb$.71i1otUQpw2eMlrjcP3H4XxsnLlVbIQxagFDGviOvCaIz7ONa.tTZPO09YL7hiAh4vLaTcGD43VoAM6tEYjx/
syntaxerrormmm:$6$rounds=4096$4ZUeoch.EwyR/TLb$.71i1otUQpw2eMlrjcP3H4XxsnLlVbIQxagFDGviOvCaIz7ONa.tTZPO09YL7hiAh4vLaTcGD43VoAM6tEYjx/
#packages:
# - qemu-guest-agent
#power_state:
# delay: now
# mode: reboot

View File

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

View File

@ -0,0 +1,3 @@
pulumi>=3.0.0,<4.0.0
pulumi_libvirt>=0.3.0
pulumi-command>=0.4.1