Clone VM mit Ansible

convoy74

Member
Feb 22, 2022
8
1
8
50
Hallo,

ich hab folgendes Problem, ich möchte eine VM von einem Template via Ansible clonen und die IP im Cloud-Init setzen.
Das Clonen funktioniert schon mal, ich bekomme es aber nicht hin, dass die IP gesetzt wird.



YAML:
---
- name: Cloner Container
  hosts: localhost
  connection: local
  gather_facts: no

  tasks:
    - name: clone container
      community.general.proxmox_kvm:
        node: "{{pve_node}}"
        api_user: "{{pve_api_user}}"
        api_password: "{{proxmox_api_password}}"
        api_host: "{{pve_api_host}}"
        clone: template1
        name: machine1
        ipconfig:
          ipconfig0: 'ip=172.16.33.51/24,gw=172.16.33.1'
        full: false
        format: unspecified
        timeout: 500

Ansible Version 2.14.0
proxmoxer==2.0.0


Jemand vielleicht ein Idee? Danke
 
Hallo, ich hab die Lösung nun selbst gefunden.


Ich hab mir den Source Code von proxmox_kvm.py angesehen, hab mich etwas mit pvesh/API auseinander gesetzt und meinen Fehler gefunden.

Das Ansible Module ruft zum Clonen einer VM nur folgende API auf:

Bash:
pvesh create /nodes/{node}/qemu/{vmid}/clone

Diese erlaubt nur einen beschränkten Satz an Informationen zu ändern.
Man kann nachher aber über folgenden API Aufruf z.B die IP ändern.

Bash:
pvesh set /nodes/{node}/qemu/{vmid}/config -ipconfig0 'ip=172.16.33.36/24,gw=172.16.33.1'

Leider verwendet das Ansible Module beim Clone diesen Endpoint nicht.

Man kann aber jetzt das Playbook wie folgt anpassen und erweitern:

YAML:
---
- name: Cloner Container
  hosts: localhost
  connection: local
  gather_facts: no

  tasks:
    - name: clone container
      community.general.proxmox_kvm:
        node: "{{pve_node}}"
        api_user: "{{pve_api_user}}"
        api_password: "{{proxmox_api_password}}"
        api_host: "{{pve_api_host}}"
        clone: template1
        name: machine1
        full: false
        format: unspecified
        timeout: 500


    - name: Update
      community.general.proxmox_kvm:
        node: "{{pve_node}}"
        api_user: "{{pve_api_user}}"
        api_password: "{{proxmox_api_password}}"
        api_host: "{{pve_api_host}}"
        name: machine1
        ipconfig:
          ipconfig0: 'ip=172.16.33.51/24,gw=172.16.33.1'
        update: yes

Viel Spass weiterhin mit Proxmox
 
  • Like
Reactions: B.Otto

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!