Logo

dev-resources.site

for different kinds of informations.

Learning Ansible, Proxmox and LXC, Part 1

Published at
10/27/2024
Categories
ansible
iac
proxmox
lxc
Author
beedog
Categories
4 categories in total
ansible
open
iac
open
proxmox
open
lxc
open
Author
6 person written this
beedog
open
Learning Ansible, Proxmox and LXC, Part 1

I've been running a server at home for a few years and gone through many iterations of hardware and different software/virtualization stacks. On this iteration I landed on Proxmox which supports LXC, an interesting virtualization technology.

Now, I have been a fan of IaC and I wanted to learn Ansible for a while. I'd prefer Terraform but the Terraform module for Proxmox did not work very well when I tried it a while ago, so it's a good opportunity for me to try Ansible!

This blog series is my learning notes for using Ansible to provision LXCs (and a few VMs) and configure the software/service running in said LXCs.

Or so I thought - the series is no more, but I'm keeping the "Part 1" in the title just for the lols, here is what happened:

Step 1, I create a snippet to quickly get an LXC up, it looks like this:

- name: test playbook
  hosts: localhost

  tasks:
  - name: Create new container with minimal options
    community.general.proxmox:
      vmid: 200
      node: my-proxmox-node
      api_user: ansible-usr@pve
      api_password: 123
      api_host: 192.168.x.x
      hostname: test-lxc
      password: 456
      ostemplate: 'local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst'
      storage: local-lvm
Enter fullscreen mode Exit fullscreen mode

Then I run ansible-playbook playbook.yml to create the LXC. So far, so good.

Step 2, the LXC is up and running but the config is quite loose. I'd like to tighten it up a bit. I add disk_volume block to the template, replacing storage. As per example in the documentation

- name: test playbook
  hosts: localhost

  tasks:
  - name: Create new container with minimal options
    community.general.proxmox:
      vmid: 200
      node: my-proxmox-node
      api_user: ansible-usr@pve
      api_password: 123
      api_host: 192.168.x.x
      hostname: test-lxc
      password: 456
      ostemplate: 'local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst'
      disk_volume:
        storage: local-lvm
        size: 20
Enter fullscreen mode Exit fullscreen mode

What could possibly go wrong?

Step 3, Ansible complains: "disk_volume is not a valid parameter". Huh? But the doc contains the definition and examples, how could...oh, "added in community.general 9.2.0", I see. Let me upgrade my local Ansible version.

Step 3.5 I'll spare you (and myself!) the details of me trying to figure out my local module's version, things are already bad enough.

Step 4, now the error message is something like "400 Bad Request, disk_volume is not defined in schema". OK, maybe I need to upgrade and reboot my Proxmox installation as well. Too bad though, next step please!

Step 5, OK I've given up on trying to make disk_volume work. Let me revert that property and move on to the next thing, adding cores property to limit the CPU resource.

- name: test playbook
  hosts: localhost

  tasks:
  - name: Create new container with minimal options
    community.general.proxmox:
      vmid: 200
      node: my-proxmox-node
      api_user: ansible-usr@pve
      api_password: 123
      api_host: 192.168.x.x
      hostname: test-lxc
      password: 456
      ostemplate: 'local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst'
      storage: local-lvm
      cores: 4
Enter fullscreen mode Exit fullscreen mode

Works like a charm. If we just ignore the whole disk_volume thing for a second...

Step 6, I want to try updating the LXC through Ansible. I change cores from 4 to 6, save, rerun, surely this should update my LXC's CPU to 6, right? Right?

PLAY RECAP **********************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
Enter fullscreen mode Exit fullscreen mode

Step 7, I think it's time to revisit Terraform. Wish me luck!

proxmox Article's
30 articles in total
Favicon
How to Build and Manage Virtual Machines Using Proxmox CLI: A Step-by-Step Guide
Favicon
Efficient Proxmox Backups: How to Use NAKIVO Backup & Replication
Favicon
Introduction à Terraform avec Proxmox
Favicon
Proxmox Virtual Machine optimization
Favicon
Complete Data Protection Guide: Backing Up Proxmox Virtual Machines
Favicon
Proxmox Backup by NAKIVO: The Ultimate Solution for VM Data Protection
Favicon
Proxmox cpu affinity for VMs
Favicon
Self-Host a Joplin Sync Server in Proxmox
Favicon
A Detailed Guide to Securing Proxmox Virtual Machines via NAKIVO Backup & Replication
Favicon
How to recover and update Proxmox 8 firewall configuration in SQLite when you locked yourself out
Favicon
Proxmox: Resize Your Local (pve) Disk
Favicon
Network performance optimization with Nvidia ConnectX on Proxmox
Favicon
Learning Ansible, Proxmox and LXC, Part 1
Favicon
Proxmox HugePages for VMs
Favicon
Disable or Hide Local Storage on Proxmox VE
Favicon
Install Proxmox on any bare metal server
Favicon
Proxmox Network Storage: Firewall Rules
Favicon
How to Install Ubuntu 24.04 on Proxmox VE
Favicon
Install Ubuntu 24.04 on Proxmox VE
Favicon
Proxmox and NAS: Implementing VLANs for Network Isolation
Favicon
Proxmox: Network Storage
Favicon
Create an Ubuntu Cloud-Init Template on Proxmox: The Command Line Guide
Favicon
Proxmox Security Series:Securing Root Access
Favicon
How to Backup Proxmox VM in Vinchin Backup & Recovery?
Favicon
Using Packer and Proxmox to Build Templates
Favicon
Proxmox Security Series: Strengthening Your Virtual Environment
Favicon
Saying Hello to the Room
Favicon
Setting Up The Home Lab: Setting up Kubernetes Using Ansible
Favicon
Setting Up The Home Lab: Terraform and Cloud-Init
Favicon
Effortless VM Data Security with NAKIVO and Proxmox Backup

Featured ones: