[SOLVED] Cloud-init isn't applied after linked clone of template via API

Hi,

currently we're trying to create template based clones using Ansible's community.general.proxmox_kvm. To make the clones configurable we stick with cloud-init. We are building the template using a hand rolled Packer configuration which deploys fine (locally as well as in our production cluster).

If we manually create clones (either locally or in the cluster) we are able to provide cloud-init parameters as expected, the new machine boots and everything is set up.

Now if we use the ansible task to set the VMs up, they're getting cloned as expected but no cloud-init parameters except from the hostname are applied. The corresponding "cloud-init analyze show" command shows the cloud-init command runs through without issue.
The cloud-init tab in the Proxmox UI shows no cloud-init settings though - so i somehow guess the cloud-init parameters aren't passed the right way.

Is there any log i'm able to consult to check what request is being issued? I'd appreciate any hint where to look at!

Thank you very much in advance - Florian
 
Huh - i oversaw i had to manually add a cloud-init after cloning using the UI. I guess it might me be necessary to set the ci up afterwards.

Thank you @TodorPetkov - sure probably you have more insights than me.. :)

YAML:
- name: Deploy continuous cloud machines
  community.general.proxmox_kvm:
    proxmox_default_behavior: no_defaults

    api_user: "{{ cc_proxmox_api_user }}"
    api_password: "{{ cc_proxmox_api_password }}"
    api_host: "{{ cc_proxmox_api_host }}"

    ostype: l26
    bootdisk: scsi0
    serial:
      serial0: socket
    vga: serial0

    ciuser: ansible
    cipassword: ansible #"{{ 'ansible' | password_hash('sha256') }}"

    # Node where the guest should be placed.
    # TODO: Should be determined automatically by recent usage.
    node: pve
    full: yes
    state: present
    clone: cc-base-debian-10
    balloon: 256

    pool: "{{ item.cid if cc_is_prod else omit }}"

    name: "{{ item.hostname }}"
    cores: "{{ item.cores | default(1) }}"
    memory: "{{ item.memory  | default(1024) }}"
    nameservers:
      - 10.10.10.1
    scsi: "{{ item.scsi | default({ 'scsi0': item.cid ~ ':10' }) }}"
    net:
      net0: "virtio,bridge=vmbr0"
    ipconfig: "{{ item.ipconfig }}"

  register: present_state
  loop: "{{ cc_hosts | hosts2list }}"
  delegate_to: localhost
 
Thank you very much @TodorPetkov - this option was exactly what i was missing.

I moved the cloud-init based attributes to the update-task. It was important to remove the state attribute from the update-task, i guess the "proxmox_kvm" module should have better eliminated the update attribute and incorporated it into the state attribute.

I leave my tasks here for future interested readers:

YAML:
- name: Deploy continuous cloud machines
  community.general.proxmox_kvm:
    proxmox_default_behavior: no_defaults

    api_user: "{{ proxmox_api_user }}"
    api_password: "{{ proxmox_api_password }}"
    api_host: "{{ proxmox_api_host }}"

    ostype: l26
    bootdisk: scsi0
    serial:
      serial0: socket
    vga: serial0

    # Node where the guest should be placed.
    # TODO: Should be determined automatically by recent usage.
    # WARNING: The node-property of the subsequent update-task must match!
    node: pve
    full: no
    state: present
    clone: cc-base-debian-10
    balloon: 256

    pool: "{{ item.cid if cc_is_prod else omit }}"

    name: "{{ item.hostname }}"
    cores: "{{ item.cores | default(1) }}"
    memory: "{{ item.memory  | default(1024) }}"
    net:
      net0: "virtio,bridge=vmbr0"

  register: present_state
  loop: "{{ cc_hosts | hosts2list }}"
  delegate_to: localhost

- name: Wait for deployment
  ansible.builtin.wait_for:
    timeout: 15
  delegate_to: localhost
  when: present_state.changed


- name: Update virtual machines
  community.general.proxmox_kvm:
    proxmox_default_behavior: no_defaults

    api_user: "{{ proxmox_api_user }}"
    api_password: "{{ proxmox_api_password }}"
    api_host: "{{ proxmox_api_host }}"

    node: pve

    name: "{{ item.hostname }}"

    ciuser: ansible
    cipassword: ansible #"{{ 'ansible' | password_hash('sha256') }}"
    ipconfig: "{{ item.ipconfig }}"
    nameservers:
      - 10.10.10.1

    update: yes

  register: update_state
  loop: "{{ cc_hosts | hosts2list }}"
  delegate_to: localhost
  when: present_state.changed

- name: Wait for update
  ansible.builtin.wait_for:
    timeout: 15
  delegate_to: localhost
  when: update_state.changed


- name: Start virtual machines
  community.general.proxmox_kvm:
    proxmox_default_behavior: no_defaults

    api_user: "{{ proxmox_api_user }}"
    api_password: "{{ proxmox_api_password }}"
    api_host: "{{ proxmox_api_host }}"

    name: "{{ item.hostname }}"
    state: started
  register: started_state
  loop: "{{ cc_hosts | hosts2list }}"
  delegate_to: localhost

- name: Wait for start
  ansible.builtin.wait_for:
    timeout: 15
  delegate_to: localhost
  when: started_state.changed
 
  • Like
Reactions: LeMeow and ewcook

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!