i need some help on configure multiple cloud_init_nics using variable files. Here is my variable files for example: files/dict
vm:
all:
- name: rhel7
hostname: rhel7
dns: "8.8.8.8 8.8.4.4"
nic:
- nic_name: eth0
ip: "10.10.10.10"
netmask: "255.255.255.0"
gateway: "10.10.10.1"
bootproto: "static"
onboot: "true"
- nic_name: "eth1"
ip: "10.10.10.11"
netmask: "255.255.255.0"
bootproto: "static"
onboot: "true"
- name: rhel8
hostname: rhel8
dns: "8.8.8.8 8.8.4.4"
nic:
- ip: "10.10.10.12"
netmask: "255.255.255.0"
gateway: "10.10.10.1"
nic_name: "ens7"
bootproto: "static"
onboot: "true"
Each vm could have from minimum 1 nic to N number of nic card.
Here is my playbook(obviously didn't work), because it will loop the second nic as a different tasks.
- name: include vards
include_vars: files/dict
- name: readvar
ovirt_vm:
cloud_init_nics:
- nic_name: "{{item.nic|json_query('[*].nic_name') }}"
nic_boot_protocol: "{{item.nic|json_query('[*].ip') }}"
cloud_init_persist: no
wait: false
with_items: "{{vm.all}}"
From the documentation , it seems like it need multiple "- nic_name" under the same task
cloud_init_nics:
- nic_name: eth0
nic_boot_protocol: dhcp
- nic_name: eth1
nic_boot_protocol: static
nic_ip_address: 10.34.60.86
nic_netmask: 255.255.252.0
Because each vm has different number of nic , so I cant use the example from the documentation.
So my question would be: how do i loop the cloud_init_nics multiple times but still running as 1 task? Is that possible? if not is there any idea that i should look up to?
is it possible to register item.all.nic as a variable, then cloud_init_nics: {{ var }} ? Thanks
Translate the nic lists to keep the required attributes and use the nic lists in the module
You can create the correct data on your own. For example
gives