I'm attempting to automate VM deployment on XCP-ng (version 20.04.01) using Ansible and the xenserver_guest module. The guest OS is AlmaLinux 9.
ansible --version
ansible 2.9.27
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/automation/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Jun 20 2023, 11:36:40) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
My objective is to:
- Deploy the VM from a template.
- Set a static IP address on the guest OS during deployment.
- Perform additional configuration tasks like adding a user to sudoers and setting the hostname (mentioned for reference).
Problem:
The VM is successfully created, but the static IP is not assigned to the guest OS (AlmaLinux 9) after logging in.
Additional Information:
- I've verified that the
xenserver_guestmodule version supports setting static IPs. - The provided code snippet successfully configures the network interface within the XenServer environment, but the guest OS itself is not reflecting the static IP assignment.
Context:
We're in the process of automating virtual machine (VM) deployments on our XCP-ng virtualization platform. Our current infrastructure heavily relies on manual processes, and we're aiming to streamline VM provisioning and configuration using Ansible.
This automation effort is crucial for:
Enhancing Efficiency: Automating VM deployment reduces manual intervention, saving time and effort for our IT team. Ensuring Consistency: Ansible playbooks guarantee consistent configurations across all deployed VMs, minimizing human error and configuration drift. Scalability: Automation empowers us to handle larger deployments efficiently and cater to growing infrastructure demands. We acknowledge the existence of alternative tools for VM automation. However, our current environment leverages XCP-ng and Ansible, and this project serves as a stepping stone towards a more comprehensive automation strategy. Successfully incorporating static IP assignment during VM deployment using the xenserver_guest module is a critical step in this direction.
I've attempted to configure the static IP within the networks section of the xenserver_guest module:
- name: "Create the VM with network configuration"
xenserver_guest:
validate_certs: false
name: "{{ vm_name }}"
name_desc: "Created_by: Ansible"
template: "{{ template_name }}"
# ... other VM configuration options
networks:
- name: "Pool-wide network associated with eth0"
type: static
ip: 172.16.29.139
netmask: 255.255.255.0
gateway: 172.16.29.201
# ... configuration for other network interfaces (if applicable)
state: poweredon
Also I got this output:
xcp-ng-host1 | CHANGED => {
"changed": true,
"instance": {
"cdrom": {
"iso_name": "AlmaLinux-9.2-x86_64-dvd.iso",
"type": "iso"
},
"customization_agent": "custom",
"disks": [
{
"name": "Alma_Linux_Onmobile 0",
"name_desc": "Created by template provisioner",
"os_device": "xvda",
"size": 42949672960,
"sr": "host2",
"sr_uuid": "80fd9e14-a4dc-fa21-c276-a1799d4b6bcb",
"vbd_userdevice": "0"
}
],
"domid": "322",
"folder": "",
"hardware": {
"memory_mb": 4096,
"num_cpu_cores_per_socket": 1,
"num_cpus": 4
},
"home_server": "",
"is_template": false,
"name": "my_first_vm",
"name_desc": "Created_by: Ansible",
"networks": [
{
"gateway": "172.16.29.201",
"gateway6": "",
"ip": "",
"ip6": [],
"mac": "12:ed:b7:4b:f4:33",
"mtu": "1500",
"name": "Pool-wide network associated with eth0",
"netmask": "255.255.255.0",
"prefix": "24",
"prefix6": "",
"vif_device": "0"
},
{
"gateway": "",
"gateway6": "",
"ip": "",
"ip6": [],
"mac": "36:50:3b:bd:ad:2e",
"mtu": "1500",
"name": "Pool-wide network associated with eth1",
"netmask": "",
"prefix": "",
"prefix6": "",
"vif_device": "1"
},
{
"gateway": "",
"gateway6": "",
"ip": "",
"ip6": [],
"mac": "e2:1d:ef:3a:60:1f",
"mtu": "1500",
"name": "Pool-wide network associated with eth2",
"netmask": "",
"prefix": "",
"prefix6": "",
"vif_device": "2"
},
{
"gateway": "",
"gateway6": "",
"ip": "",
"ip6": [],
"mac": "be:a2:19:ff:85:af",
"mtu": "1500",
"name": "Pool-wide network associated with eth3",
"netmask": "",
"prefix": "",
"prefix6": "",
"vif_device": "3"
}
],
"other_config": {
"auto_poweron": "false",
"base_template_name": "AlmaLinux 8",
"import_task": "OpaqueRef:67e31e5d-7ed5-4a6a-9cc2-e665f9ed69d3",
"install-methods": "cdrom,nfs,http,ftp",
"instant": "true",
"linux_template": "true",
"mac_seed": "c4366f2c-2707-1016-7c61-8c0a9773cdcd"
},
"platform": {
"acpi": "1",
"apic": "true",
"device-model": "qemu-upstream-compat",
"device_id": "0001",
"hpet": "true",
"nx": "true",
"pae": "true",
"secureboot": "false",
"timeoffset": "-1",
"vga": "std",
"videoram": "8",
"viridian": "false"
},
"state": "poweredoff",
"uuid": "f5deb35e-7f86-a75f-ab7b-74ff1bcb2345",
"xenstore_data": {
"vm-data": "",
"vm-data/mmio-hole-size": "268435456",
"vm-data/networks": "",
"vm-data/networks/0": "",
"vm-data/networks/0/gateway": "172.16.29.201",
"vm-data/networks/0/ip": "172.16.29.139",
"vm-data/networks/0/mac": "12:ed:b7:4b:f4:33",
"vm-data/networks/0/name": "Pool-wide network associated with eth0",
"vm-data/networks/0/netmask": "255.255.255.0",
"vm-data/networks/0/prefix": "24",
"vm-data/networks/0/type": "static"
}
}
}
I expected the guest OS (AlmaLinux 9) to receive the static IP configuration (172.16.29.139) after the VM deployment. However, upon logging in, the IP is not set.
Question:
- Is there an error in my configuration that prevents the
xenserver_guestmodule from setting the static IP within the guest OS? - Are there alternative approaches to ensure the static IP is set during VM deployment using Ansible on XCP-ng?