[SOLVED] Clone VM & add network interface with Ansible

sebyp

New Member
Mar 13, 2023
11
0
1
38
Bucharest, Romania
www.bit-sentinel.com
Hello community,

I'm bashing my head against the wall with this one, so hopefully someone will be able to provide some guidance.

Problem statement: I have an exiting rocky-linux template that I would like to clone. At clone time I would also like to create a network interface on the newly cloned VM. What happens is that the VM gets cloned correctly, except the network interface. See my Ansible code below
YAML:
- name: Clone VM from template
  community.general.proxmox_kvm:
    api_host: REDACTED
    validate_certs: true
    api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}"
    api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}"
    api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}"
    state: present
    node: "{{ netbox_pve_host }}"
    clone: "{{ platforms | first }}"
    net:
      net0: virtio,bridge=vmbr0,tag=1098
    format: unspecified
    full: false
    kvm: true
    name: "{{ inventory_hostname }}"
    newid: "{{ netbox_vm_id }}"
    timeout: 300
  delegate_to: localhost

Any ideas?

Thx!
 
L.E. (I should have read the Ansible modules a bit more careful)

Apparently there is a module named community.general.proxmox_nic that can be used to customize the VM after cloning, see example below
YAML:
- name: Add network interface
  community.general.proxmox_nic:
    api_host: REDACTED
    validate_certs: true
    api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}"
    api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}"
    api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}"
    name: "{{ inventory_hostname }}"
    interface: net0
    bridge: vmbr0
    tag: 1098
    state: present
  delegate_to: localhost
 

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!