Files
toallab-automation/roles/oatakan.ansible-role-ovirt/tasks/template_check.yml

52 lines
1.8 KiB
YAML

---
- name: fail if no template and disk specified
fail:
msg: "at least one disk must be specified when no template is used"
when:
- node.template is undefined
- node.disks[0].size is undefined | default(False)
- name: fail if both template and iso is specified
fail:
msg: "template and cd_iso are mutually exclusive, only define one of them"
when:
- node.template is defined
- node.cd_iso is defined
- block:
- name: check if template exists
ovirt_template_info:
auth: "{{ ovirt_auth }}"
pattern: "name={{ node.template }} and datacenter={{ datacenter_info.ovirt_datacenters[0].name }}"
register: template_info
- name: fail with message
fail:
msg: "template ({{ node.template }}) could not be found, make sure it exists"
when: ( template_info.ovirt_templates | default([]) ) | length == 0
when: node.template is defined
- block:
- name: check iso file on data domain
ovirt_disk_info:
auth: "{{ ovirt_auth }}"
pattern: "name={{ node.cd_iso }}"
register: ovirt_disk_main_iso
- name: fail with message
fail:
msg: "iso file ({{ node.cd_iso }}) could not be found on the data domain and iso domain does not exists"
when:
- (ovirt_disk_main_iso.ovirt_disks[0].id | default(None)) is undefined
- iso_domain is undefined or iso_domain|length == 0
when: node.cd_iso is defined
- name: set iso file
set_fact:
node_iso_file: '{{ node_iso_file | default({}) | combine({node.name: ovirt_disk_main_iso.ovirt_disks[0].id | default(node.cd_iso) | default(None)}) }}'
when: (node_iso_file[node.name] | default(None)) is undefined
- name: set os type
set_fact:
nodes_os_type: '{{ nodes_os_type | default({}) | combine({node.name: node.os_type | default(template_info.ovirt_templates[0].os.type) | default(None)}) }}'