diff --git a/defaults/main.yml b/defaults/main.yml index f298ea9..4841394 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,6 +5,7 @@ upgrade_timeout: 1200 cluster_name: Default check_upgrade: false reboot_after_upgrade: true +use_maintenance_policy: true host_statuses: - up host_names: diff --git a/tasks/cluster_policy.yml b/tasks/cluster_policy.yml new file mode 100644 index 0000000..0cceaed --- /dev/null +++ b/tasks/cluster_policy.yml @@ -0,0 +1,32 @@ +- name: Get cluster facts + ovirt_clusters_facts: + auth: "{{ ovirt_auth }}" + pattern: "name={{ cluster_name }}" + check_mode: "no" + +- name: Get name of the original scheduling policy + ovirt_scheduling_policies_facts: + auth: "{{ ovirt_auth }}" + id: "{{ ovirt_clusters[0].scheduling_policy.id }}" + check_mode: "no" + +- name: Remember the cluster scheduling policy + set_fact: + cluster_scheduling_policy: "{{ ovirt_scheduling_policies[0].name }}" + +- name: Get API facts + # TODO: Change when Ansible 2.5 is released: + # ovirt_api_facts: + ovirt_api_facts_internal_25: + auth: "{{ ovirt_auth }}" + check_mode: "no" + +- name: Set in cluster upgrade policy + ovirt_clusters: + auth: "{{ ovirt_auth }}" + name: "{{ cluster_name }}" + scheduling_policy: cluster_maintenance + register: cluster_policy + when: + - (ovirt_api.product_info.version.major >= 4 and ovirt_api.product_info.version.major >= 2) or + (ovirt_api.product_info.version.major == 4 and ovirt_api.product_info.version.major == 1 and ovirt_api.product_info.version.revision >= 4) diff --git a/tasks/main.yml b/tasks/main.yml index 775f573..e325d47 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -31,21 +31,8 @@ when: ovirt_hosts | length == 0 - block: - - name: Get cluster facts - ovirt_clusters_facts: - auth: "{{ ovirt_auth }}" - pattern: "name={{ cluster_name }}" - check_mode: "no" - - - name: Get name of the original scheduling policy - ovirt_scheduling_policies_facts: - auth: "{{ ovirt_auth }}" - id: "{{ ovirt_clusters[0].scheduling_policy.id }}" - check_mode: "no" - - - name: Remember the cluster scheduling policy - set_fact: - cluster_scheduling_policy: "{{ ovirt_scheduling_policies[0].name }}" + - include: cluster_policy.yml + when: use_maintenance_policy - name: Get list of VMs in cluster ovirt_vms_facts: @@ -53,23 +40,6 @@ pattern: "cluster={{ cluster_name }}" check_mode: "no" - - name: Get API facts - # TODO: Change when Ansible 2.5 is released: - # ovirt_api_facts: - ovirt_api_facts_internal_25: - auth: "{{ ovirt_auth }}" - check_mode: "no" - - - name: Set in cluster upgrade policy - ovirt_clusters: - auth: "{{ ovirt_auth }}" - name: "{{ cluster_name }}" - scheduling_policy: cluster_maintenance - register: cluster_policy - when: - - (ovirt_api.product_info.version.major >= 4 and ovirt_api.product_info.version.major >= 2) or - (ovirt_api.product_info.version.major == 4 and ovirt_api.product_info.version.major == 1 and ovirt_api.product_info.version.revision >= 4) - - name: Shutdown VMs which can be stopped ovirt_vms: auth: "{{ ovirt_auth }}" @@ -104,7 +74,7 @@ auth: "{{ ovirt_auth }}" name: "{{ cluster_name }}" scheduling_policy: "{{ cluster_scheduling_policy }}" - when: cluster_policy.changed | default(false) + when: use_maintenance_policy and cluster_policy.changed | default(false) - name: Start again stopped VMs ovirt_vms: