--- - include_tasks: preflight_check.yml - name: clone from template ovirt_vm: auth: "{{ ovirt_auth }}" name: "{{ item.name }}" template: "{{ item.template | default(omit) }}" cluster: "{{ providers.ovirt.cluster | default('Default') }}" state: present wait: yes memory: "{{ item.memory }}MiB" memory_max: "{{ ((item.memory_max | string) + 'MiB') if item.memory_max is defined else omit }}" memory_guaranteed: "{{ ((item.memory_guaranteed | string) + 'MiB') if item.memory_guaranteed is defined else omit }}" cpu_mode: "{{ item.cpu_mode | default(omit) }}" cpu_cores: "{{ item.cpu_cores | default(omit) }}" cpu_sockets: "{{ item.cpu }}" cpu_threads: "{{ item.cpu_threads | default(omit) }}" cd_iso: "{{ node_iso_file[item] | default(omit) }}" bios_type: "{{ item.bios_type | default(omit) }}" ballooning_enabled: "{{ item.ballooning_enabled | default(omit) }}" graphical_console: "{{ item.graphical_console | default(omit) }}" host: "{{ item.host | default(omit) }}" host_devices: "{{ item.host_devices | default(omit) }}" placement_policy: "{{ item.placement_policy | default(omit) }}" storage_domain: "{{ item.storage_domain | default(omit) }}" type: "{{ item.type | default('server') }}" high_availability: true nics: - name: nic1 profile_name: "{{ item.networks[0].profile_name | default(item.networks[0].name) }}" network: "{{ item.networks[0].name }}" custom_properties: "{{ item.custom_properties | default(omit) }}" operating_system: "{{ item.operating_system | default(omit) }}" async: 7200 poll: 0 register: deploy loop: "{{ nodes }}" when: - nodes is defined - name: wait for instance creation to complete async_status: jid: "{{ item.ansible_job_id }}" register: deployed_instances until: deployed_instances.finished retries: "{{ instance_wait_retry_limit }}" delay: 10 no_log: true with_items: "{{ deploy.results }}" when: - nodes is defined - deploy.results is defined - item.ansible_job_id is defined - name: create additional disks ovirt_disk: auth: "{{ ovirt_auth }}" name: "{% if item.1.name_prefix | default(true) %}{{ item.0.name }}_{% endif %}{{ item.1.name }}" vm_name: "{{ item.0.name }}" size: "{{ item.1.size | default(omit) }}" format: "{{ item.1.format | default(omit) }}" interface: "{{ item.1.interface | default(omit) }}" bootable: "{{ item.1.bootable | default(omit) }}" storage_domain: "{{ item.1.storage_domain | default(omit) }}" activate: yes state: present wait: yes async: 7200 poll: 0 register: create_disks with_subelements: - "{{ nodes }}" - disks - skip_missing: yes when: - nodes is defined - item.1 is defined - name: wait for disk creation to complete async_status: jid: "{{ item.ansible_job_id }}" register: disks_creation until: disks_creation.finished retries: "{{ instance_wait_retry_limit }}" delay: 10 with_items: "{{ create_disks.results }}" when: - nodes is defined - create_disks.results is defined - item.ansible_job_id is defined - include_tasks: wait_for_disk_pre29.yml when: ansible_version.full is version('2.9', '<') - include_tasks: wait_for_disk.yml when: ansible_version.full is version('2.9', '>=') - name: linux - start and customize ovirt_vm: auth: "{{ ovirt_auth }}" name: "{{ item.name }}" state: running cloud_init: nic_boot_protocol: "{{ 'static' if item.networks[0].ip is defined and item.networks[0].netmask is defined and item.networks[0].gateway is defined else 'dhcp' }}" nic_ip_address: "{{ item.networks[0].ip | default('') }}" nic_netmask: "{{ item.networks[0].netmask | default('') }}" nic_gateway: "{{ item.networks[0].gateway | default('') }}" nic_name: "{{ item.networks[0].nic_name | default(item.networks[0].device_name) | default('eth0') }}" nic_on_boot: true host_name: "{{ item.name }}.{{ item.domain | default('') }}" dns_servers: "{{ item.dns_servers|join(' ') | default([]) }}" custom_script: "{{ item.custom_script | default('') }}" user_name: "{{ item.user_name | default('') }}" root_password: "{{ item.root_password | default('') }}" async: 7200 poll: 0 register: deploy_linux loop: "{{ nodes }}" when: - nodes is defined - item.sysprep is not defined - name: windows - start and customize ovirt_vm: auth: "{{ ovirt_auth }}" name: "{{ item.name }}" state: running sysprep: custom_script: "{{ lookup('template', 'templates/unattended.xml.j2') }}" host_name: "{{ item.name | default('') }}" domain: "{{ item.domain | default('') }}" user_name: "{{ item.user_name | default(ansible_user) }}" root_password: "{{ item.root_password | default(ansible_password) }}" async: 7200 poll: 0 register: deploy_windows loop: "{{ nodes }}" when: - nodes is defined - item.sysprep is defined - name: combine deployment results set_fact: deploy_results: "{{ deploy_results|default([]) + [ item ] }}" with_items: "{{ deploy_linux.results + deploy_windows.results }}" when: - nodes is defined - item.ansible_job_id is defined - name: wait for vms to be started async_status: jid: "{{ item.ansible_job_id }}" register: instances until: instances.finished retries: "{{ instance_wait_retry_limit }}" delay: 10 with_items: "{{ deploy_results }}" when: - nodes is defined - deploy_results is defined - item.ansible_job_id is defined - name: assign tags to provisioned vms ovirt_tag: name: "{{ item.1 }}_{{ item.0.item.item[item.1] }}" vms: ["{{ item.0.item.item.name }}"] state: attached with_nested: - "{{ instances.results }}" - [ 'app_name', 'role' ] when: - nodes is defined - instances.results is defined - item.0.vm is defined - item.0.item.item[item.1] is defined - include_tasks: wait_for_ip_pre29.yml when: ansible_version.full is version('2.9', '<') - include_tasks: wait_for_ip.yml when: ansible_version.full is version('2.9', '>=')