Added libvirt-ansible-python template.
This commit is contained in:
parent
dd31b87720
commit
5ee69d1f94
2
libvirt-ansible-python/.gitignore
vendored
Normal file
2
libvirt-ansible-python/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.pyc
|
||||||
|
venv/
|
5
libvirt-ansible-python/Pulumi.yaml
Normal file
5
libvirt-ansible-python/Pulumi.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
name: ${PROJECT}
|
||||||
|
description: ${DESCRIPTION}
|
||||||
|
runtime: python
|
||||||
|
template:
|
||||||
|
description: A Pulumi deployment with libvirt and Python
|
9
libvirt-ansible-python/README.md
Normal file
9
libvirt-ansible-python/README.md
Normal 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
|
||||||
|
|
74
libvirt-ansible-python/__main__.py
Normal file
74
libvirt-ansible-python/__main__.py
Normal 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])
|
6
libvirt-ansible-python/ansible.cfg
Normal file
6
libvirt-ansible-python/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
|
2
libvirt-ansible-python/cloud-init/meta-data
Normal file
2
libvirt-ansible-python/cloud-init/meta-data
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
instance-id: debian11
|
||||||
|
local-hostname: debian11
|
4
libvirt-ansible-python/cloud-init/network-config
Normal file
4
libvirt-ansible-python/cloud-init/network-config
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
ethernets:
|
||||||
|
interface0:
|
||||||
|
dhcp4: true
|
24
libvirt-ansible-python/cloud-init/user-data
Normal file
24
libvirt-ansible-python/cloud-init/user-data
Normal 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
|
6
libvirt-ansible-python/deploy.yml
Normal file
6
libvirt-ansible-python/deploy.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- base_personal
|
||||||
|
become: yes
|
||||||
|
become_user: root
|
3
libvirt-ansible-python/requirements.txt
Normal file
3
libvirt-ansible-python/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pulumi>=3.0.0,<4.0.0
|
||||||
|
pulumi_libvirt>=0.3.0
|
||||||
|
pulumi-command>=0.4.1
|
Loading…
Reference in New Issue
Block a user