# 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:
```yaml
- 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
```
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](https://docs.ansible.com/ansible/latest/collections/community/general/proxmox_module.html#examples)
```yaml
- 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
```
What could possibly go wrong?

Step 3, Ansible complains: "disk_volume is not a valid parameter". Huh? But the [doc](https://docs.ansible.com/ansible/latest/collections/community/general/proxmox_module.html#parameter-disk_volume) 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.
```yaml
- 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
```
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
```

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