Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
change ovirt facts to info
Browse files Browse the repository at this point in the history
  • Loading branch information
mnecas committed Nov 10, 2019
1 parent d65dc19 commit 203aa4d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
14 changes: 4 additions & 10 deletions tasks/cluster_policy.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
- name: Get cluster facts
ovirt_cluster_facts:
auth: "{{ ovirt_auth }}"
pattern: "name={{ cluster_name }}"
check_mode: "no"

- name: Get name of the original scheduling policy
ovirt_scheduling_policy_facts:
ovirt_scheduling_policy_info:
auth: "{{ ovirt_auth }}"
id: "{{ ovirt_clusters[0].scheduling_policy.id }}"
id: "{{ cluster_info.ovirt_clusters[0].scheduling_policy.id }}"
check_mode: "no"

- name: Remember the cluster scheduling policy
Expand All @@ -25,5 +19,5 @@
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)
- (api_info.ovirt_api.product_info.version.major >= 4 and api_info.ovirt_api.product_info.version.major >= 2) or
(api_info.ovirt_api.product_info.version.major == 4 and api_info.ovirt_api.product_info.version.major == 1 and api_info.ovirt_api.product_info.version.revision >= 4)
41 changes: 22 additions & 19 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@
tags:
- always

- name: Get API facts
ovirt_api_facts:
- name: Get API info
ovirt_api_info:
auth: "{{ ovirt_auth }}"
register: api_info
check_mode: "no"

- name: Get cluster
ovirt_cluster_facts:
- name: Get cluster info
ovirt_cluster_info:
auth: "{{ ovirt_auth }}"
pattern: "name={{ cluster_name }}"
check_mode: "no"
register: cluster_info

- name: Set cluster upgrade status in progress
no_log: true
uri:
url: "{{ ovirt_auth.url }}/clusters/{{ ovirt_clusters[0].id }}/upgrade"
url: "{{ ovirt_auth.url }}/clusters/{{ cluster_info.ovirt_clusters[0].id }}/upgrade"
method: POST
body_format: json
validate_certs: false
Expand All @@ -45,7 +47,7 @@
body:
upgrade_action: start
register: upgrade_set
when: ovirt_api.product_info.version.major >= 4 and ovirt_api.product_info.version.minor >= 3
when: api_info.ovirt_api.product_info.version.major >= 4 and api_info.ovirt_api.product_info.version.minor >= 3

- name: Log event cluster upgrade has started
ovirt_event:
Expand All @@ -55,13 +57,14 @@
origin: "cluster_upgrade"
custom_id: "{{ 2147483647 | random | int }}"
severity: normal
cluster: "{{ ovirt_clusters[0].id }}"
cluster: "{{ cluster_info.ovirt_clusters[0].id }}"

- name: Get hosts
ovirt_host_facts:
ovirt_host_info:
auth: "{{ ovirt_auth }}"
pattern: "cluster={{ cluster_name | mandatory }} {{ check_upgrade | ternary('', 'update_available=true') }} {{ host_names | map('regex_replace', '^(.*)$', 'name=\\1') | list | join(' or ') }} {{ host_statuses | map('regex_replace', '^(.*)$', 'status=\\1') | list | join(' or ') }}"
check_mode: "no"
register: host_info

- block:
- name: Print - no hosts to be updated
Expand All @@ -76,25 +79,25 @@
origin: "cluster_upgrade"
custom_id: "{{ 2147483647 | random | int }}"
severity: normal
cluster: "{{ ovirt_clusters[0].id }}"
when: ovirt_hosts | length == 0
cluster: "{{ cluster_info.ovirt_clusters[0].id }}"
when: host_info.ovirt_hosts | length == 0

- block:
- name: Log event about hosts that are marked to be updated
ovirt_event:
auth: "{{ ovirt_auth }}"
state: present
description: "Hosts {{ ovirt_hosts | map(attribute='name') | join(',') }} are marked to be updated in cluster {{ cluster_name }}."
description: "Hosts {{ host_info.ovirt_hosts | map(attribute='name') | join(',') }} are marked to be updated in cluster {{ cluster_name }}."
origin: "cluster_upgrade"
custom_id: "{{ 2147483647 | random | int }}"
severity: normal
cluster: "{{ ovirt_clusters[0].id }}"
cluster: "{{ cluster_info.ovirt_clusters[0].id }}"

- include_tasks: cluster_policy.yml
when: use_maintenance_policy

- name: Get list of VMs in cluster
ovirt_vm_facts:
ovirt_vm_info:
auth: "{{ ovirt_auth }}"
pattern: "cluster={{ cluster_name }}"
check_mode: "no"
Expand All @@ -110,7 +113,7 @@
# or if stop_non_migratable_vms is enabled, which means we stop pinned VMs
- include_tasks: upgrade.yml
with_items:
- "{{ ovirt_hosts }}"
- "{{ host_info.ovirt_hosts }}"
when: "item.id not in host_ids or stop_non_migratable_vms"

- name: Start ovirt job session
Expand All @@ -127,9 +130,9 @@
origin: "cluster_upgrade"
severity: normal
custom_id: "{{ 2147483647 | random | int }}"
cluster: "{{ ovirt_clusters[0].id }}"
cluster: "{{ cluster_info.ovirt_clusters[0].id }}"

when: ovirt_hosts | length > 0
when: host_info.ovirt_hosts | length > 0
rescue:
- name: Log event about cluster upgrade failed
ovirt_event:
Expand All @@ -139,7 +142,7 @@
origin: "cluster_upgrade"
custom_id: "{{ 2147483647 | random | int }}"
severity: error
cluster: "{{ ovirt_clusters[0].id }}"
cluster: "{{ cluster_info.ovirt_clusters[0].id }}"

always:
- name: Set original cluster policy
Expand Down Expand Up @@ -173,7 +176,7 @@
- name: Set cluster upgrade status to finished
no_log: true
uri:
url: "{{ ovirt_auth.url }}/clusters/{{ ovirt_clusters[0].id }}/upgrade"
url: "{{ ovirt_auth.url }}/clusters/{{ cluster_info.ovirt_clusters[0].id }}/upgrade"
validate_certs: false
method: POST
body_format: json
Expand All @@ -183,7 +186,7 @@
upgrade_action: finish
when:
- upgrade_set is defined and not upgrade_set.failed | default(false)
- ovirt_api.product_info.version.major >= 4 and ovirt_api.product_info.version.minor >= 3
- api_info.ovirt_api.product_info.version.major >= 4 and api_info.ovirt_api.product_info.version.minor >= 3

- name: Logout from oVirt
ovirt_auth:
Expand Down
3 changes: 1 addition & 2 deletions tasks/upgrade.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Get list of VMs in host
ovirt_vm_facts:
ovirt_vm_info:
auth: "{{ ovirt_auth }}"
pattern: "cluster={{ cluster_name }} and host={{ item.name }} and status=up"
check_mode: "no"
Expand Down Expand Up @@ -45,7 +45,6 @@
- description: "Upgrading host: {{ item.name }}"

- name: Upgrade host
# TODO: change to ovirt_host, when Ansible 2.8 is out:
ovirt_host:
auth: "{{ ovirt_auth }}"
name: "{{ item.name }}"
Expand Down

0 comments on commit 203aa4d

Please sign in to comment.