mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ovirt_vms: Add new cloud_init_nics parameter (#3557)
This commit is contained in:
parent
370d8332ae
commit
1057c2f89d
1 changed files with 58 additions and 23 deletions
|
@ -195,12 +195,26 @@ options:
|
||||||
- "C(custom_script) - Cloud-init script which will be executed on Virtual Machine when deployed."
|
- "C(custom_script) - Cloud-init script which will be executed on Virtual Machine when deployed."
|
||||||
- "C(dns_servers) - DNS servers to be configured on Virtual Machine."
|
- "C(dns_servers) - DNS servers to be configured on Virtual Machine."
|
||||||
- "C(dns_search) - DNS search domains to be configured on Virtual Machine."
|
- "C(dns_search) - DNS search domains to be configured on Virtual Machine."
|
||||||
- "C(nic_boot_protocol) - Set boot protocol of the network interface of Virtual Machine. Can be one of None, DHCP or Static."
|
- "C(nic_boot_protocol) - Set boot protocol of the network interface of Virtual Machine. Can be one of none, dhcp or static."
|
||||||
- "C(nic_ip_address) - If boot protocol is static, set this IP address to network interface of Virtual Machine."
|
- "C(nic_ip_address) - If boot protocol is static, set this IP address to network interface of Virtual Machine."
|
||||||
- "C(nic_netmask) - If boot protocol is static, set this netmask to network interface of Virtual Machine."
|
- "C(nic_netmask) - If boot protocol is static, set this netmask to network interface of Virtual Machine."
|
||||||
- "C(nic_gateway) - If boot protocol is static, set this gateway to network interface of Virtual Machine."
|
- "C(nic_gateway) - If boot protocol is static, set this gateway to network interface of Virtual Machine."
|
||||||
- "C(nic_name) - Set name to network interface of Virtual Machine."
|
- "C(nic_name) - Set name to network interface of Virtual Machine."
|
||||||
- "C(nic_on_boot) - If I(True) network interface will be set to start on boot."
|
- "C(nic_on_boot) - If I(True) network interface will be set to start on boot."
|
||||||
|
cloud_init_nics:
|
||||||
|
description:
|
||||||
|
- "List of dictionaries representing network interafaces to be setup by cloud init."
|
||||||
|
- "This option is used, when user needs to setup more network interfaces via cloud init."
|
||||||
|
- "If one network interface is enough, user should use C(cloud_init) I(nic_*) parameters. C(cloud_init) I(nic_*) parameters
|
||||||
|
are merged with C(cloud_init_nics) parameters."
|
||||||
|
- "Dictionary can contain following values:"
|
||||||
|
- "C(nic_boot_protocol) - Set boot protocol of the network interface of Virtual Machine. Can be one of none, dhcp or static."
|
||||||
|
- "C(nic_ip_address) - If boot protocol is static, set this IP address to network interface of Virtual Machine."
|
||||||
|
- "C(nic_netmask) - If boot protocol is static, set this netmask to network interface of Virtual Machine."
|
||||||
|
- "C(nic_gateway) - If boot protocol is static, set this gateway to network interface of Virtual Machine."
|
||||||
|
- "C(nic_name) - Set name to network interface of Virtual Machine."
|
||||||
|
- "C(nic_on_boot) - If I(True) network interface will be set to start on boot."
|
||||||
|
version_added: "2.3"
|
||||||
notes:
|
notes:
|
||||||
- "If VM is in I(UNASSIGNED) or I(UNKNOWN) state before any operation, the module will fail.
|
- "If VM is in I(UNASSIGNED) or I(UNKNOWN) state before any operation, the module will fail.
|
||||||
If VM is in I(IMAGE_LOCKED) state before any operation, we try to wait for VM to be I(DOWN).
|
If VM is in I(IMAGE_LOCKED) state before any operation, we try to wait for VM to be I(DOWN).
|
||||||
|
@ -281,6 +295,22 @@ ovirt_vms:
|
||||||
user_name: root
|
user_name: root
|
||||||
root_password: super_password
|
root_password: super_password
|
||||||
|
|
||||||
|
# Run VM with cloud init, with multiple network interfaces:
|
||||||
|
ovirt_vms:
|
||||||
|
name: rhel7_4
|
||||||
|
template: rhel7
|
||||||
|
cluster: mycluster
|
||||||
|
cloud_init_nics:
|
||||||
|
- nic_name: eth0
|
||||||
|
nic_boot_protocol: dhcp
|
||||||
|
nic_on_boot: true
|
||||||
|
- nic_name: eth1
|
||||||
|
nic_boot_protocol: static
|
||||||
|
nic_ip_address: 10.34.60.86
|
||||||
|
nic_netmask: 255.255.252.0
|
||||||
|
nic_gateway: 10.34.63.254
|
||||||
|
nic_on_boot: true
|
||||||
|
|
||||||
# Run VM with sysprep:
|
# Run VM with sysprep:
|
||||||
ovirt_vms:
|
ovirt_vms:
|
||||||
name: windows2012R2_AD
|
name: windows2012R2_AD
|
||||||
|
@ -609,34 +639,36 @@ class VmsModule(BaseModule):
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
|
||||||
|
|
||||||
def _get_initialization(sysprep, cloud_init):
|
def _get_initialization(sysprep, cloud_init, cloud_init_nics):
|
||||||
initialization = None
|
initialization = None
|
||||||
if cloud_init:
|
if cloud_init or cloud_init_nics:
|
||||||
initialization = otypes.Initialization(
|
initialization = otypes.Initialization(
|
||||||
nic_configurations=[
|
nic_configurations=[
|
||||||
otypes.NicConfiguration(
|
otypes.NicConfiguration(
|
||||||
boot_protocol=otypes.BootProtocol(
|
boot_protocol=otypes.BootProtocol(
|
||||||
cloud_init.pop('nic_boot_protocol').lower()
|
nic.pop('nic_boot_protocol').lower()
|
||||||
) if cloud_init.get('nic_boot_protocol') else None,
|
) if nic.get('nic_boot_protocol') else None,
|
||||||
name=cloud_init.pop('nic_name'),
|
name=nic.pop('nic_name', None),
|
||||||
on_boot=cloud_init.pop('nic_on_boot'),
|
on_boot=nic.pop('nic_on_boot', None),
|
||||||
ip=otypes.Ip(
|
ip=otypes.Ip(
|
||||||
address=cloud_init.pop('nic_ip_address'),
|
address=nic.pop('nic_ip_address', None),
|
||||||
netmask=cloud_init.pop('nic_netmask'),
|
netmask=nic.pop('nic_netmask', None),
|
||||||
gateway=cloud_init.pop('nic_gateway'),
|
gateway=nic.pop('nic_gateway', None),
|
||||||
) if (
|
) if (
|
||||||
cloud_init.get('nic_gateway') is not None or
|
nic.get('nic_gateway') is not None or
|
||||||
cloud_init.get('nic_netmask') is not None or
|
nic.get('nic_netmask') is not None or
|
||||||
cloud_init.get('nic_ip_address') is not None
|
nic.get('nic_ip_address') is not None
|
||||||
) else None,
|
) else None,
|
||||||
)
|
)
|
||||||
] if (
|
for nic in cloud_init_nics
|
||||||
cloud_init.get('nic_gateway') is not None or
|
if (
|
||||||
cloud_init.get('nic_netmask') is not None or
|
nic.get('nic_gateway') is not None or
|
||||||
cloud_init.get('nic_ip_address') is not None or
|
nic.get('nic_netmask') is not None or
|
||||||
cloud_init.get('nic_boot_protocol') is not None or
|
nic.get('nic_ip_address') is not None or
|
||||||
cloud_init.get('nic_on_boot') is not None
|
nic.get('nic_boot_protocol') is not None or
|
||||||
) else None,
|
nic.get('nic_on_boot') is not None
|
||||||
|
)
|
||||||
|
] if cloud_init_nics else None,
|
||||||
**cloud_init
|
**cloud_init
|
||||||
)
|
)
|
||||||
elif sysprep:
|
elif sysprep:
|
||||||
|
@ -730,6 +762,7 @@ def main():
|
||||||
force=dict(type='bool', default=False),
|
force=dict(type='bool', default=False),
|
||||||
nics=dict(default=[], type='list'),
|
nics=dict(default=[], type='list'),
|
||||||
cloud_init=dict(type='dict'),
|
cloud_init=dict(type='dict'),
|
||||||
|
cloud_init_nics=dict(defaul=[], type='list'),
|
||||||
sysprep=dict(type='dict'),
|
sysprep=dict(type='dict'),
|
||||||
host=dict(default=None),
|
host=dict(default=None),
|
||||||
clone=dict(type='bool', default=False),
|
clone=dict(type='bool', default=False),
|
||||||
|
@ -755,8 +788,10 @@ def main():
|
||||||
|
|
||||||
control_state(vm, vms_service, module)
|
control_state(vm, vms_service, module)
|
||||||
if state == 'present' or state == 'running' or state == 'next_run':
|
if state == 'present' or state == 'running' or state == 'next_run':
|
||||||
cloud_init = module.params['cloud_init']
|
|
||||||
sysprep = module.params['sysprep']
|
sysprep = module.params['sysprep']
|
||||||
|
cloud_init = module.params['cloud_init']
|
||||||
|
cloud_init_nics = module.params['cloud_init_nics']
|
||||||
|
cloud_init_nics.append(cloud_init)
|
||||||
|
|
||||||
# In case VM don't exist, wait for VM DOWN state,
|
# In case VM don't exist, wait for VM DOWN state,
|
||||||
# otherwise don't wait for any state, just update VM:
|
# otherwise don't wait for any state, just update VM:
|
||||||
|
@ -781,13 +816,13 @@ def main():
|
||||||
),
|
),
|
||||||
wait_condition=lambda vm: vm.status == otypes.VmStatus.UP,
|
wait_condition=lambda vm: vm.status == otypes.VmStatus.UP,
|
||||||
# Start action kwargs:
|
# Start action kwargs:
|
||||||
use_cloud_init=cloud_init is not None,
|
use_cloud_init=cloud_init is not None or len(cloud_init_nics) > 0,
|
||||||
use_sysprep=sysprep is not None,
|
use_sysprep=sysprep is not None,
|
||||||
vm=otypes.Vm(
|
vm=otypes.Vm(
|
||||||
placement_policy=otypes.VmPlacementPolicy(
|
placement_policy=otypes.VmPlacementPolicy(
|
||||||
hosts=[otypes.Host(name=module.params['host'])]
|
hosts=[otypes.Host(name=module.params['host'])]
|
||||||
) if module.params['host'] else None,
|
) if module.params['host'] else None,
|
||||||
initialization=_get_initialization(sysprep, cloud_init),
|
initialization=_get_initialization(sysprep, cloud_init, cloud_init_nics),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue