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

Commit

Permalink
Merge pull request #59 from mnecas/ovirt_bump
Browse files Browse the repository at this point in the history
ovirt-ansible-cluster-upgrade: bump ansible to 2.9
mwperina authored Nov 21, 2019
2 parents 4d92421 + 78ea38c commit 4c64922
Showing 15 changed files with 51 additions and 3,710 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ So you can use any of this name. This documentation and examples in this reposit
Requirements
------------

* Ansible version 2.5 or higher
* Python SDK version 4.2 or higher
* Ansible version 2.9 or higher
* Python SDK version 4.3 or higher

Role Variables
--------------
3 changes: 1 addition & 2 deletions automation.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
distros:
- fc29
- fc30
- el7
release_branches:
master: [ "ovirt-master", "ovirt-4.3", "ovirt-4.2" ]
master: [ "ovirt-master" ]
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="1.1.15"
VERSION="1.2.0"
MILESTONE=master
RPM_RELEASE="0.1.$MILESTONE.$(date -u +%Y%m%d%H%M%S)"

28 changes: 0 additions & 28 deletions library/README.md

This file was deleted.

249 changes: 0 additions & 249 deletions library/ovirt_event_28.py

This file was deleted.

637 changes: 0 additions & 637 deletions library/ovirt_host_28.py

This file was deleted.

235 changes: 0 additions & 235 deletions library/ovirt_job_29.py

This file was deleted.

2,507 changes: 0 additions & 2,507 deletions library/ovirt_vm_28.py

This file was deleted.

2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ galaxy_info:

license: Apache License 2.0

min_ansible_version: 2.5
min_ansible_version: 2.9

platforms:
- name: EL
2 changes: 1 addition & 1 deletion ovirt-ansible-cluster-upgrade.spec.in
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ Group: Virtualization/Management
BuildArch: noarch
Url: http://www.ovirt.org

Requires: ansible >= 2.7.2
Requires: ansible >= 2.9.0

%description
This Ansible role provide funtionality to upgrade cluster of hosts in oVirt engine,
17 changes: 6 additions & 11 deletions tasks/cluster_policy.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
- 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"
register: sp_info

- name: Remember the cluster scheduling policy
set_fact:
cluster_scheduling_policy: "{{ ovirt_scheduling_policies[0].name }}"
cluster_scheduling_policy: "{{ sp_info.ovirt_scheduling_policies[0].name }}"

- name: Remember the cluster scheduling policy properties
set_fact:
@@ -25,5 +20,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)
56 changes: 30 additions & 26 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -45,101 +47,103 @@
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_28:
ovirt_event:
auth: "{{ ovirt_auth }}"
state: present
description: "Cluster upgrade started for {{ cluster_name }}."
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
debug:
msg: "No hosts to be updated"

- name: Log event - no hosts to be updated
ovirt_event_28:
ovirt_event:
auth: "{{ ovirt_auth }}"
state: present
description: "There are no hosts to be updated for cluster {{ cluster_name }}."
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_28:
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"
register: vms_in_cluster

- include_tasks: pinned_vms.yml

- name: Start ovirt job session
ovirt_job_29:
ovirt_job:
auth: "{{ ovirt_auth }}"
description: "Upgrading hosts"

# Update only those hosts that aren't in list of hosts were VMs are pinned
# 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
ovirt_job_29:
ovirt_job:
auth: "{{ ovirt_auth }}"
description: "Upgrading hosts"
state: finished

- name: Log event about cluster upgrade finished successfully
ovirt_event_28:
ovirt_event:
auth: "{{ ovirt_auth }}"
state: present
description: "Upgrade of cluster {{ cluster_name }} finished successfully."
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_28:
ovirt_event:
auth: "{{ ovirt_auth }}"
state: present
description: "Upgrade of cluster {{ cluster_name }} failed."
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
@@ -173,7 +177,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
@@ -183,7 +187,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:
2 changes: 1 addition & 1 deletion tasks/pinned_vms.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
set_fact:
host_ids_items: "{{ item.host.id }}"
with_items:
- "{{ ovirt_vms | default([]) }}"
- "{{ vms_in_cluster.ovirt_vms | default([]) }}"
when:
- "item['placement_policy']['affinity'] != 'migratable'"
- "item.host is defined"
15 changes: 7 additions & 8 deletions tasks/upgrade.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
- 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"

- name: Move user migratable vms
ovirt_vm_28:
ovirt_vm:
auth: "{{ ovirt_auth }}"
force_migrate: true
migrate: true
@@ -15,7 +15,7 @@
when:
- "item['placement_policy']['affinity'] == 'user_migratable'"
with_items:
- "{{ ovirt_vms }}"
- "{{ vms_in_cluster.ovirt_vms }}"
loop_control:
label: "{{ item.name }}"

@@ -26,7 +26,7 @@
force: true
name: "{{ item.name }}"
with_items:
- "{{ ovirt_vms }}"
- "{{ vms_in_cluster.ovirt_vms }}"
when:
- "item['placement_policy']['affinity'] == 'pinned'"
loop_control:
@@ -38,15 +38,14 @@
pinned_vms_names: "{{ pinned_vms_names + pinned_to_host_vms.results | selectattr('changed') | map(attribute='item.name') | list }}"

- name: Start ovirt job step
ovirt_job_29:
ovirt_job:
auth: "{{ ovirt_auth }}"
description: "Upgrading hosts"
steps:
- description: "Upgrading host: {{ item.name }}"

- name: Upgrade host
# TODO: change to ovirt_host, when Ansible 2.8 is out:
ovirt_host_28:
ovirt_host:
auth: "{{ ovirt_auth }}"
name: "{{ item.name }}"
state: upgraded
@@ -55,7 +54,7 @@
timeout: "{{ upgrade_timeout }}"

- name: Finish ovirt job step
ovirt_job_29:
ovirt_job:
auth: "{{ ovirt_auth }}"
description: "Upgrading hosts"
steps:
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ansible
ansible>=2.9.0
ansible-lint

0 comments on commit 4c64922

Please sign in to comment.