[SOLVED] Set static IP to cloned VM with Cloud-init initialisation.

Vinvar

New Member
Jun 22, 2025
2
0
1
Dear all,

I am trying to clone my VM template while setting up a static ip. As I am using Ansible, I try to use the community.general.proxmox_kvm module. However, I do not get the VM to have a static ip. For the template I use a Debian 12 (bookworm) template using Learn Linux Tv's guide. Below I added six scenario's which should work (according to multiple forums, e.g. 1 2 3). But tey don't. I get either the task to ran due to 'Bad Request: Parameter verification failed' or an ip via DHCP when I start the VM.

Also creating a clone directly in Proxmox using qm clone 1001 123 --name test-123 and setting the ip via qm set 123 --ipconfig0 ip=[redacted].23/24,gw=[redacted] as described in Proxmox's guide did not do the trick.

Anyone an idea how to clone a VM which can be initialized with Cloud-init and give this a static IP?

---
To see the problem yourself, run the following with Ansible. Change the [redacted] values with your own.
Earlier, I had troubles setting the memory in the initial task. I found out that you need to run this in a second task. In case this was needed with the network as well, I added the test 4 to 6. So, test 4 to 6 are the same as test 1 to 3 with the network part being separated.

Code:
- name: 'TEST script'
  hosts: [redacted]

  check_mode: false
  gather_facts: true

  become: true
  become_method: enable # Needed on Proxmox as user has no 'privilege escalation'

  tasks:
    - name: 'TEST 1: Create the VM with static ip xx.24 via ipconfig key.'
      community.general.proxmox_kvm:
        api_host: [redacted]
        api_user: [redacted]
        api_token_id: [redacted]
        api_token_secret: [redacted]
        clone: 'tmpl-deb12'
        full: true
        name: 'iptest-1'
        newid: 201
        node: [redacted]
        state: 'present'
        timeout: 300
        ### Network
        net:
          net0: 'virtio,bridge=vmbr0,firewall=0'
        ipconfig:
          ipconfig0: 'ip=[redacted].24/24,gw=[redacted].254'

    - name: 'TEST 2: Create the VM with static ip xx.25 via cicustom inline.'
      community.general.proxmox_kvm:
        api_host: [redacted]
        api_user: [redacted]
        api_token_id: [redacted]
        api_token_secret: [redacted]
        clone: 'tmpl-deb12'
        full: true
        name: 'iptest-2'
        newid: 202
        node: [redacted]
        state: 'present'
        timeout: 300
        ### Network
        net:
          net0: 'virtio,bridge=vmbr0,firewall=0'
        cicustom: 'network-config="$(cat <<EOF
version: 2
ethernets:
  [redacted]:
    addresses: [[redacted].25/24]
    gateway4: [redacted].254
    nameservers:
      addresses: [[redacted]]
EOF
)"'

    - name: 'TEST 3: Create the VM with static ip xx.26 via cicustom from file.'
      community.general.proxmox_kvm:
        api_host: [redacted]
        api_user: [redacted]
        api_token_id: [redacted]
        api_token_secret: [redacted]
        clone: 'tmpl-deb12'
        full: true
        name: 'iptest-3'
        newid: 203
        node: [redacted]
        state: 'present'
        timeout: 300
        ### Network
        net:
          net0: 'virtio,bridge=vmbr0,firewall=0'
        cicustom: 'network-config=local:/[redacted]/test3.yaml'

    - name: 'TEST 4: Create the VM with static ip xx.27 via ipconfig key in second task.'
      block:
        - name: 'TEST 4: task 1: create the VM.'
          community.general.proxmox_kvm:
            api_host: [redacted]
            api_user: [redacted]
            api_token_id: [redacted]
            api_token_secret: [redacted]
            clone: 'tmpl-deb12'
            full: true
            name: 'iptest-4'
            newid: 301
            node: [redacted]
            state: 'present'
            timeout: 300
        - name: 'TEST 4: task 2: set static ip xx.27 via ipconfig key. As PoC change memory as well.'
          community.general.proxmox_kvm:
            api_host: [redacted]
            api_user: [redacted]
            api_token_id: [redacted]
            api_token_secret: [redacted]
            memory: 2048
            name: 'iptest-4'
            node: [redacted]
            state: 'present'
            timeout: 300
            update: true
            ### Network
            net:
              net0: 'virtio,bridge=vmbr0,firewall=0'
            ipconfig:
              ipconfig0: 'ip=[redacted].27/24,gw=[redacted].254'

    - name: 'TEST 5: Create the VM with static ip xx.28 via cicustom inline.'
      block:
        - name: 'TEST 5: task 1: create the VM.'
          community.general.proxmox_kvm:
            api_host: [redacted]
            api_user: [redacted]
            api_token_id: [redacted]
            api_token_secret: [redacted]
            clone: 'tmpl-deb12'
            full: true
            name: 'iptest-5'
            newid: 302
            node: [redacted]
            state: 'present'
            timeout: 300
        - name: 'TEST 5: task 2: set static ip xx.28 via cicustom inline. As PoC change memory as well.'
          community.general.proxmox_kvm:
            api_host: [redacted]
            api_user: [redacted]
            api_token_id: [redacted]
            api_token_secret: [redacted]
            memory: 2048
            name: 'iptest-5'
            node: [redacted]
            state: 'present'
            timeout: 300
            update: true
            ### Network
            net:
              net0: 'virtio,bridge=vmbr0,firewall=0'
            cicustom: 'network-config="$(cat <<EOF
version: 2
ethernets:
  [redacted]:
    addresses: [[redacted].25/24]
    gateway4: [redacted].254
    nameservers:
      addresses: [[redacted]]
EOF
)"'
    - name: 'TEST 6: Create the VM with static ip xx.29 via cicustom from file.'
      block:
        - name: 'TEST 6: task 1: create the VM.'
          community.general.proxmox_kvm:
            api_host: [redacted]
            api_user: [redacted]
            api_token_id: [redacted]
            api_token_secret: [redacted]
            clone: 'tmpl-deb12'
            full: true
            name: 'iptest-6'
            newid: 303
            node: [redacted]
            state: 'present'
            timeout: 300
        - name: 'TEST 6: task 2: set static ip xx.29 via cicustom from file. As PoC change memory as well.'
          community.general.proxmox_kvm:
            api_host: [redacted]
            api_user: [redacted]
            api_token_id: [redacted]
            api_token_secret: [redacted]
            memory: 2048
            name: 'iptest-6'
            node: [redacted]
            state: 'present'
            timeout: 300
            update: true
            ### Network
            net:
              net0: 'virtio,bridge=vmbr0,firewall=0'
            cicustom: 'network-config=local:snippets/[redacted]/test6.yaml'

With the following yaml for the Test 3 and Test 6.
Code:
version: 2
ethernets:
  [redacted]:
    addresses:
      - [redacted].29/24
    gateway4: [redacted]
This is the test6.yml. In the test3.yaml the address is [redacted].26
 
Last edited:
For the template I use a Debian 12 (bookworm) template using
a clone directly in Proxmox using qm clone 1001 123 --name test-123 and setting the ip via qm set 123 --ipconfig0 ip=[redacted].23/24,gw=[redacted] as described in
I have not watched the video you are referencing. Is the starting template an unmodified official image from Debian website? Which one?
You should reduce the complexity in your testing and establish a baseline. That means - vanilla Debian cloud image, minimum "qm" configuration commands.
Get it to a point where it's working the way you like. Examine the resulting configuration file, then match it with corresponding ansible. To examine the configuration run "qm config [vmid]" (this is the most important part and you did not provide it).

I can tell you that using official cloud image as template and cloning it with static IP works fine here.

Good luck


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Thank you @bbgeek17. I used the netinst from Debian. I was not aware of cloud images and by looking into it, they seem much better for VMs than the netinst I use (for my bare metals). When I ran the Debian cloud image following along with the guide I was able to get it working.

Learned something today and got my issue resolved. Again, thanks!