Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'ansible-lint' violations for 'disaster_recovery' & 'remove_stale_lun' roles #554

Merged
merged 10 commits into from
Jul 4, 2022
3 changes: 1 addition & 2 deletions automation/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ cp -r "$OVIRT_BUILD"/* "$COLLECTION_DIR"
cd "$COLLECTION_DIR"

antsibull-changelog lint -v
ansible-lint roles/* --exclude roles/hosted_engine_setup --exclude roles/disaster_recovery --exclude roles/remove_stale_lun -x experimental
ansible-lint -x var-spacing,unnamed-task,fqcn-builtins,no-changed-when,risky-shell-pipe,ignore-errors roles/disaster_recovery
ansible-lint roles/* --exclude roles/hosted_engine_setup -x experimental

cd "$ROOT_PATH"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Fix "ansible-lint" version 6.0.0 violations for "disaster_recovery" & "remove_stale_lun" roles (https://github.com/oVirt/ovirt-ansible-collection/pull/554).
6 changes: 4 additions & 2 deletions roles/disaster_recovery/tasks/clean/remove_disks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- block:
- name: Remove disk
---
- name: Remove disk main block
block:
- name: "Remove disk '{{ disk.id }}'"
ovirt_disk:
state: absent
id: "{{ disk.id }}"
Expand Down
6 changes: 4 additions & 2 deletions roles/disaster_recovery/tasks/clean/remove_domain.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- block:
---
- name: Remove storage domain main block
block:
# If we get the exception "Cannot deactivate Master Data Domain while there are running tasks on its Data Center."
# We should wait for some time and try again
- name: Remove storage domain
- name: "Remove storage domain '{{ sd.name }}'"
ovirt_storage_domain:
state: absent
id: "{{ sd.id }}"
Expand Down
10 changes: 6 additions & 4 deletions roles/disaster_recovery/tasks/clean/remove_domain_process.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
- block:
---
- name: Remove storage domain process main block
block:
# TODO: Check what happens when we force remove unattached storage domain (probably should add a default empty GUID as a data center
# Answer: When we force remove an unattached storage domain, ansible tries to move it to maintenance and detach it first,
# although it might be that this storage domain is already detached and has no related data center, therefor the move to maintenance will fail

# We set an initial value for sp_uuid since this task is being called
# multiple times from the main task and sp_uuid is stateful.
- name: Set default boolean value for sp_uuid
set_fact: sp_uuid=True
ansible.builtin.set_fact: sp_uuid=True

- name: Detached storage domain - Set sp_uuid with empty GUID
set_fact: sp_uuid="00000000-0000-0000-0000-000000000000"
ansible.builtin.set_fact: sp_uuid="00000000-0000-0000-0000-000000000000"
when: sd.data_centers is not defined

- name: Detached storage domain - Fetch active host for remove
Expand All @@ -29,7 +31,7 @@
# If sp_uuid is still initiated with the default boolean value,
# that means that there is a data center which the storage domain is attached to it.
- name: Attached storage domain - Set sp_uuid
set_fact: sp_uuid="{{ sd.data_centers[0].id }}"
ansible.builtin.set_fact: sp_uuid="{{ sd.data_centers[0].id }}"
when: sp_uuid

- name: Remove storage domain with no force
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- block:
---
- name: Remove invalid storage domain main block
block:
- name: Fetch invalid storage domain for remove
ovirt_storage_domain_info:
pattern: name={{ storage['dr_' + dr_source_map + '_name'] }} and {{ dr_inactive_domain_search }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- block:
---
- name: Remove valid storage domain main block
block:
- name: Fetch active/maintenance/detached storage domain for remove
ovirt_storage_domain_info:
pattern: >
Expand Down
6 changes: 4 additions & 2 deletions roles/disaster_recovery/tasks/clean/remove_vms.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- block:
- name: Remove diskless VMs
---
- name: Remove diskless VM main block
block:
- name: "Remove diskless VM '{{ vm.name }}'"
ovirt_vm:
state: absent
name: "{{ vm.name }}"
Expand Down
6 changes: 4 additions & 2 deletions roles/disaster_recovery/tasks/clean/shutdown_vm.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- block:
- name: Shutdown VM
---
- name: Shutdown VM main block
block:
- name: "Shutdown VM '{{ vms.name }}'"
ovirt_vm:
state: stopped
name: "{{ vms.name }}"
Expand Down
4 changes: 3 additions & 1 deletion roles/disaster_recovery/tasks/clean/shutdown_vms.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- block:
---
- name: Shutdown VMs main block
block:
# Get all the running VMs related to a storage domain and shut them down
- name: Fetch VMs in the storage domain
ovirt_vm_info:
Expand Down
4 changes: 3 additions & 1 deletion roles/disaster_recovery/tasks/clean/update_ovf_store.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- block:
---
- name: Update OVF store for active storage domain main block
block:
- name: Fetch storage domain only if active
ovirt_storage_domain_info:
pattern: status = active and storage.name={{ storage['dr_' + dr_source_map + '_name'] }}
Expand Down
22 changes: 12 additions & 10 deletions roles/disaster_recovery/tasks/clean_engine.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- block:
---
- name: Clean engine main block
block:
- name: Obtain SSO token
ovirt_auth:
url: "{{ vars['dr_sites_' + dr_source_map + '_url'] }}"
Expand All @@ -21,19 +23,19 @@
loop_var: storage

- name: Set force remove flag to false for non master domains
set_fact: dr_force=False
ansible.builtin.set_fact: dr_force=False

# Set all the queries suffix to fetch a storage domain in a specific status.
# Note: Export storage domain is not supported and should not be part of storage mapping
- name: Setup queries for storage domains
set_fact:
ansible.builtin.set_fact:
dr_active_domain_search='status = active and type != cinder'
dr_maintenance_domain_search='status = maintenance and type != cinder'
dr_unattached_domain_search='status = unattached and type != cinder and type != glance'
dr_inactive_domain_search='type != glance and type != cinder and status != active'

- name: Set master storage domain filter
set_fact: only_master=False
ansible.builtin.set_fact: only_master=False

- name: Remove non master storage domains with valid statuses
include_tasks: clean/remove_valid_filtered_master_domains.yml
Expand All @@ -44,8 +46,8 @@

# We use inactive filter only at the end, since we are not sure if there were any storage domains
# which became inactive on the process or if there were any at the beginning.
- name: Set force remove flag to true for non master domains
set_fact: dr_force=True
- name: Set force remove flag to true for non master storage domains
ansible.builtin.set_fact: dr_force=True

- name: Remove non master storage domains with invalid statuses using force remove
include_tasks: clean/remove_invalid_filtered_master_domains.yml
Expand All @@ -55,10 +57,10 @@
loop_var: storage

- name: Set master storage domain filter
set_fact: only_master=True
ansible.builtin.set_fact: only_master=True

- name: Set force remove flag to false for master domain
set_fact: dr_force=False
ansible.builtin.set_fact: dr_force=False

- name: Remove master storage domains with valid statuses
include_tasks: clean/remove_valid_filtered_master_domains.yml
Expand All @@ -68,7 +70,7 @@
loop_var: storage

- name: Set force remove flag to true for master domain
set_fact: dr_force=True
ansible.builtin.set_fact: dr_force=True

- name: Remove master storage domains with invalid statuses using force remove
include_tasks: clean/remove_invalid_filtered_master_domains.yml
Expand All @@ -92,7 +94,7 @@
register: vm_info
when: dr_clean_orphaned_vms and storage_domain_info.ovirt_storage_domains | length == 0

- name: Remove vms if no storage domains left in setup
- name: Remove VMs if no storage domains left in setup
include_tasks: clean/remove_vms.yml
vars:
vm: "{{ item }}"
Expand Down
13 changes: 11 additions & 2 deletions roles/disaster_recovery/tasks/generate_mapping.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
- block:
---
- name: Generate mapping var file main block
block:
- name: Generate mapping var file
command: python3 {{ role_path }}/files/generate_mapping.py -a "{{ site }}" -u "{{ username }}" -p "{{ password }}" -c "{{ ca }}" -f "{{ var_file }}"
ansible.builtin.command: >-
python3 {{ role_path }}/files/generate_mapping.py
-a "{{ site }}"
-u "{{ username }}"
-p "{{ password }}"
-c "{{ ca }}"
-f "{{ var_file }}"
changed_when: true
run_once: true
tags:
- generate_mapping
8 changes: 5 additions & 3 deletions roles/disaster_recovery/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- block:
---
- name: Main block
block:
- name: Start to unregister entities
include_tasks: unregister_entities.yml
tags:
Expand All @@ -11,7 +13,7 @@
- clean_engine

- name: Failback Replication Sync pause
pause:
ansible.builtin.pause:
prompt: "[Failback Replication Sync] Please press ENTER once the destination storage domains are ready to be used for the destination setup"
tags:
- fail_back
Expand All @@ -27,7 +29,7 @@
tags:
- fail_back

- name: Genereate mapping var file
- name: Generate mapping var file
include_tasks: generate_mapping.yml
tags:
- generate_mapping
20 changes: 13 additions & 7 deletions roles/disaster_recovery/tasks/recover/add_domain.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
- block:
---
- name: Add storage domain main block
block:
- name: Fetch available hosts in data center
ovirt_host_info:
pattern: "status=up and datacenter={{ storage['dr_' + dr_target_host + '_dc_name'] }}"
auth: "{{ ovirt_auth }}"
register: host_info
- block:

- name: Check for available hosts block
block:
- name: "Check for available hosts"
fail: msg="No hosts available"
ansible.builtin.fail: msg="No hosts available"
when: host_info.ovirt_hosts.0 is undefined
- block:

- name: Add storage domain block
block:
- name: Add storage domain if NFS
include_tasks: add_nfs_domain.yml
with_items:
Expand All @@ -25,23 +31,23 @@
loop_control:
loop_var: gluster_storage

- name: Add storage domain if Posix
- name: Add storage domain if POSIX
include_tasks: add_posixfs_domain.yml
with_items:
- "{{ storage }}"
when: "storage.dr_domain_type == 'posixfs'"
loop_control:
loop_var: posix_storage

- name: Add storage domain is scsi
- name: Add storage domain if iSCSI
include_tasks: add_iscsi_domain.yml
with_items:
- "{{ storage }}"
when: "storage.dr_domain_type == 'iscsi'"
loop_control:
loop_var: iscsi_storage

- name: Add storage domain if fcp
- name: Add storage domain if FCP
include_tasks: add_fcp_domain.yml
with_items:
- "{{ storage }}"
Expand Down
14 changes: 8 additions & 6 deletions roles/disaster_recovery/tasks/recover/add_fcp_domain.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
- block:
---
- name: Import FCP storage domain main block
block:
- name: Import FCP storage domain
ovirt_storage_domain:
state: imported
id: "{{ fcp_storage['dr_domain_id'] }}"
name: "{{ fcp_storage['dr_' + dr_target_host + '_name']|default('') }}"
name: "{{ fcp_storage['dr_' + dr_target_host + '_name'] | default('') }}"
critical_space_action_blocker: "{{ fcp_storage['dr_critical_space_action_blocker'] }}"
warning_low_space: "{{ fcp_storage['dr_warning_low_space'] }}"
discard_after_delete: "{{ fcp_storage['dr_discard_after_delete'] }}"
Expand All @@ -16,13 +18,13 @@
register: result

- name: Log append to succeed_storage_domains
set_fact:
succeed_storage_domains: "{{ succeed_storage_domains }} + [ \"{{ fcp_storage['dr_' + dr_target_host + '_name']|default('') }}\" ]"
ansible.builtin.set_fact:
succeed_storage_domains: "{{ succeed_storage_domains }} + [ \"{{ fcp_storage['dr_' + dr_target_host + '_name'] | default('') }}\" ]"
when: result is succeeded

- name: Log append to failed_storage_domains
set_fact:
failed_storage_domains: "{{ failed_storage_domains }} + [ \"{{ fcp_storage['dr_' + dr_target_host + '_name']|default('') }}\" ]"
ansible.builtin.set_fact:
failed_storage_domains: "{{ failed_storage_domains }} + [ \"{{ fcp_storage['dr_' + dr_target_host + '_name'] | default('') }}\" ]"
when: result is failed
ignore_errors: "{{ dr_ignore_error_recover }}"
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- block:
---
- name: Add Gluster storage domain main block
block:
- name: Add Gluster storage domain
ovirt_storage_domain:
name: "{{ gluster_storage['dr_' + dr_target_host + '_name'] }}"
Expand All @@ -16,12 +18,12 @@
register: result

- name: Log append to succeed_storage_domains
set_fact:
ansible.builtin.set_fact:
succeed_storage_domains: "{{ succeed_storage_domains }} + [ \"{{ gluster_storage['dr_' + dr_target_host + '_name'] }}\" ]"
when: result is succeeded

- name: Log append to failed_storage_domains
set_fact:
ansible.builtin.set_fact:
failed_storage_domains: "{{ failed_storage_domains }} + [ \"{{ gluster_storage['dr_' + dr_target_host + '_name'] }}\" ]"
when: result is failed
ignore_errors: "{{ dr_ignore_error_recover }}"
Expand Down
Loading