Clone VM with Ansible and change ip-adress

Molix

New Member
May 9, 2023
2
1
1
Hello,

I have this playbook:

--- - name: Clone template hosts: pve2 gather_facts: no vars_prompt: - name: vm_name prompt: "please input the Vms name" private: false tasks: - name: Clone template community.general.proxmox_kvm: node: pve2 api_user: root@pam api_password: xxxxxxx api_host: 192.168.0.195 clone: TestKlon name: "{{ vm_name }}" full: false format: unspecified timeout: 500 - name: Warte auf die VM-Erstellung pause: seconds: 10 # waiting until vm ist created - name: Update community.general.proxmox_kvm: node: pve2 api_user: root@pam api_password: xxxxxxxxx api_host: 192.168.0.195 name: "{{ vm_name }}" ipconfig: ipconfig0: 'ip=192.168.0.101/24,gw=192.168.0.1' update: yes - name: Start VM community.general.proxmox_kvm: api_user: root@pam api_password: xxxxxxxxxx api_host: 192.168.0.195 node: pve2 name: "{{ vm_name }}" state: started

it works fine, only the IP is not changed.the template is an Ubuntu server and I entered the IP via netplan.Is that even possible or am I on the wrong track?
There are no error messages or anything similar
Greetings and thank you
 
  • Like
Reactions: Rovshan
If your VM (or template) is deployed with cloud-init, then it should work like this. If it's not a cloud init VM (or template), then it shouldn't work that way either.
 
I have the same issue, i'm using an Alma9 cloud-init image and I can't seem to the get the IP to change.

tasks:
- name: Clone template
community.general.proxmox_kvm:
node: "{{ pve_node }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
api_host: "{{ api_host }}"
clone: 'alma9-cloud'
vmid: "{{ 9999 }}"
name: "{{ vmname }}"
newid: '{{ vmid }}'
full: true
storage: 'nas_vm'
format: qcow2
timeout: 500

- name: Wait on VM creation
pause:
seconds: 10 # waiting until vm is created


- name: Update
community.general.proxmox_kvm:
node: "{{ pve_node }}"
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
name: "{{ vmname }}"
ipconfig:
ipconfig0: ip={{ip_address}}/{{subnet_mask}},gw={{gateway}}
update: yes


- name: Start VM
community.general.proxmox_kvm:
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
api_host: "{{ api_host }}"
node: "{{ pve_node }}"
name: "{{ vmname }}"
state: started

TASK [Start VM] **********************************************************************************
changed: [localhost] => changed=true
invocation:
module_args:
acpi: true
agent: null
api_host: kvmh0
api_password: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
api_token_id: null
api_token_secret: null
api_user: root@pam
args: null
autostart: false
balloon: 0
bios: null
boot: cnd
bootdisk: null
cicustom: null
cipassword: null
citype: null
ciuser: null
clone: null
cores: 1
cpu: kvm64
cpulimit: null
cpuunits: 1000
delete: null
description: null
digest: null
force: false
format: qcow2
freeze: null
full: true
hostpci: null
hotplug: null
hugepages: null
ide: null
ipconfig:
ipconfig0: ip=192.168.1.169/24,gw=192.168.1.1
keyboard: null
kvm: true
localtime: null
lock: null
machine: null
memory: 512
migrate_downtime: null
migrate_speed: null
name: test104
nameservers: null
net: null
newid: null
node: kvmh0
numa: null
numa_enabled: null
onboot: null
ostype: l26
parallel: null
pool: null
protection: null
proxmox_default_behavior: compatibility
reboot: null
revert: null
sata: null
scsi: null
scsihw: null
searchdomains: null
serial: null
shares: null
skiplock: null
smbios: null
snapname: null
sockets: 1
sshkeys: null
startdate: null
startup: null
state: started
storage: null
tablet: false
target: null
tdf: null
template: false
timeout: 30
update: true
validate_certs: false
vcpus: null
vga: std
virtio: null
vmid: null
watchdog: null
msg: VM 101104 started

TASK [Wait on VM creation] ***********************************************************************
Pausing for 10 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [localhost] => changed=false
delta: 10
echo: true
rc: 0
start: '2024-04-20 16:50:35.626978'
stderr: ''
stdout: Paused for 10.0 seconds
stop: '2024-04-20 16:50:45.627560'
user_input: ''
META: ran handlers
META: ran handlers

PLAY RECAP ***************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

there are two things I want to add to this "play"
1) I want to change the disk size
2) I want to change the hostname

I know that I can change this with another playbook. but it shouldn't be an issue to set these here...
 
I have more info:
I was on ubuntu laptop and moved to my Almalinux9 laptop, with the generic ansible install instructions completed, I get a different amount of information in the error.
"Bad Request: Parameter verification failed. - {'ipconfig0': 'invalid format - format error\\nipconfig0. gw: property is not defined in schema and the schema does not allow additional properties\\n'}" "
I change this:
ipconfig:
ipconfig0: ip={{ip_address}}/{{subnet_mask}},gw={{gateway}}

to:
ipconfig:
ipconfig0: ip={{ip_address}}/{{subnet_mask}}
and it sets the IP!
 

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!