Debian Codegraph @

ansible_collections/ibm/storage_virtualize/playbooks/partition_migration_host_actions/main.yml

raw symbols SCIP
1 ---
2 - name: Using Storage Virtualize collection to monitor partition migrating from one system to another.
3 hosts: flash_systems
4 gather_facts: false
5 connection: local
6 vars_files:
7 - vars.yml
8 vars:
9 are_all_hosts_in_inventory: true
10 commit_flag: true
11 serial: 1
12 tasks:
13
14 ####################################
15 # Check for migration
16 ####################################
17
18 - name: Gather lspartition information from flashsystem.
19 ibm.storage_virtualize.ibm_svcinfo_command:
20 clustername: "{{ ansible_host }}"
21 username: "{{ ansible_user }}"
22 password: "{{ ansible_password }}"
23 command: "lspartition -gui -json"
24 log_path: "{{ logpath }}"
25 register: partition_info
26 when: "'flash_systems' in group_names"
27
28 - name: Clean the lspartition output
29 ansible.builtin.set_fact:
30 lspartition_output: "{{ (partition_info.stdout | join('') | from_json) | flatten(1) }}"
31
32 - name: Set deployment_type based on input value
33 ansible.builtin.set_fact:
34 deployment_type: "{{ 'single_host_migre' if deployment_type == 1 else 'multi_host_migre' if deployment_type == 2 else deployment_type }}"
35 when: deployment_type in [1, 2]
36
37
38 ####################################
39 # Fetch Data for host identification
40 ####################################
41
42 - name: Fetch Data for host identification.
43 when: (lspartition_output | selectattr('migration_status', 'equalto', 'awaiting_user_input') | list | length) > 0
44 block:
45
46 - name: Fetch enclosure serial number
47 ibm.storage_virtualize.ibm_svc_info:
48 gather_subset: "node"
49 clustername: "{{ ansible_host }}"
50 username: "{{ ansible_user }}"
51 password: "{{ ansible_password }}"
52 register: enclosure_serial_number
53
54 - name: Set facts for getting data about migrating partition and enclosure serial no.
55 ansible.builtin.set_fact:
56 migrating_partition: "{{ lspartition_output | selectattr('migration_status', 'equalto', 'awaiting_user_input') }}"
57 enclosure_serial_number_out: "{{ enclosure_serial_number.Node[0]['enclosure_serial_number'] }}"
58
59 - name: Set facts for partition name.
60 ansible.builtin.set_fact:
61 partition_name: "{{ migrating_partition[0]['name'] }}"
62
63 - name: Gather lshost information from flashsystem.
64 ibm.storage_virtualize.ibm_svc_info:
65 clustername: "{{ ansible_host }}"
66 username: "{{ ansible_user }}"
67 password: "{{ ansible_password }}"
68 log_path: "{{ logpath }}"
69 gather_subset: "host"
70 filtervalue: 'partition_name={{ partition_name }}'
71 register: lshost_output
72 changed_when: false
73
74 - name: Gather details of each host on flashsystem.
75 ibm.storage_virtualize.ibm_svc_info:
76 gather_subset: "host"
77 clustername: "{{ ansible_host }}"
78 username: "{{ ansible_user }}"
79 password: "{{ ansible_password }}"
80 objectname: "{{ item.id }}"
81 log_path: "{{ logpath }}"
82 changed_when: false
83 register: shared_targetports_output
84 loop: "{{ lshost_output.Host }}"
85
86 - name: Initialize extracted_hosts list.
87 ansible.builtin.set_fact:
88 extracted_hosts: []
89 extracted_hosts_tmp: []
90
91 - name: Extract relevant fc host data for the identified partition.
92 ansible.builtin.set_fact:
93 extracted_hosts: >-
94 {{
95 extracted_hosts | combine({
96 item.Host.id | int: {
97 "inventory_hostname": inventory_hostname,
98 "name": item.Host.name,
99 "wwpns": item.Host.nodes | default([]) | map(attribute='WWPN') | list,
100 "partition": item.Host.partition_name | default(""),
101 "type": "FC"
102 }
103 })
104 }}
105 loop: "{{ shared_targetports_output.results }}"
106 when: item.Host is not none and item.Host.nodes[0].WWPN is defined
107
108 - name: Extract relevant iSCSI host data for the identified partition.
109 ansible.builtin.set_fact:
110 extracted_hosts: >-
111 {{
112 extracted_hosts | combine({
113 item.Host.id | int: {
114 "inventory_hostname": inventory_hostname,
115 "name": item.Host.name,
116 "iscsi_name": item.Host.nodes | default([]) | map(attribute='iscsi_name') | list,
117 "partition": item.Host.partition_name | default(""),
118 "portset_name":item.Host.portset_name,
119 "type": 'iscsi'
120 }
121 })
122 }}
123 loop: "{{ shared_targetports_output.results }}"
124 when: item.Host is not none and item.Host.nodes[0].iscsi_name is defined
125
126 - name: Gather lsportset information from flashsystem.
127 ibm.storage_virtualize.ibm_svc_info:
128 gather_subset: "portset"
129 clustername: "{{ ansible_host }}"
130 username: "{{ ansible_user }}"
131 password: "{{ ansible_password }}"
132 objectname: "{{ item.value.portset_name }}"
133 log_path: "{{ logpath }}"
134 changed_when: false
135 register: portset_info
136 loop: "{{ extracted_hosts | dict2items }}"
137 when: item.value.type == 'iscsi'
138
139 - name: Build host entries for extracted_hosts
140 ansible.builtin.set_fact:
141 extracted_hosts_tmp: >-
142 {{
143 extracted_hosts_tmp | default([]) + [
144 {
145 (item.item.key | string): (
146 item.item.value | combine(
147 (
148 {'replication_portset_link_uid': item.Portset.replication_portset_link_uid}
149 if item.item.value.type == 'iscsi'
150 else {}
151 )
152 )
153 )
154 }
155 ]
156 }}
157 loop: "{{ portset_info.results }}"
158 when: item.item is defined and item.item.value is defined
159
160 - name: Combine extracted_hosts_tmp into a single dict
161 ansible.builtin.set_fact:
162 extracted_hosts: "{{ extracted_hosts_tmp | default([]) | combine }}"
163
164 - name: Process extracted host data if not empty.
165 when: extracted_hosts != []
166 block:
167
168 - name: Gather lsip information from flashsystem.
169 ibm.storage_virtualize.ibm_svcinfo_command:
170 clustername: "{{ ansible_host }}"
171 username: "{{ ansible_user }}"
172 password: "{{ ansible_password }}"
173 command: "lsip -json"
174 log_path: "{{ logpath }}"
175 register: ip_info
176
177 - name: Convert raw ip_info.stdout string to structured data
178 ansible.builtin.set_fact:
179 ip_info_parsed: "{{ ip_info.stdout | from_json }}"
180
181 - name: Add iscsi_ips to extracted_hosts
182 ansible.builtin.set_fact:
183 extracted_hosts: >-
184 {%- set updated_hosts = {} -%}
185 {%- for key, host in extracted_hosts.items() -%}
186 {%- set _host = host.copy() -%}
187 {%- if 'type' in _host and _host['type'] == 'iscsi' and 'portset_name' in _host -%}
188 {%- set ips = [] -%}
189 {%- for ip in ip_info_parsed -%}
190 {%- if 'portset_name' in ip and
191 (ip['portset_name'] | string | lower | trim) == (_host['portset_name'] | string | lower | trim) and
192 'IP_address' in ip -%}
193 {%- set _ = ips.append(ip['IP_address']) -%}
194 {%- endif -%}
195 {%- endfor -%}
196 {%- set _ = _host.update({'iscsi_ips': ips}) -%}
197 {%- endif -%}
198 {%- set _ = updated_hosts.update({ key: _host }) -%}
199 {%- endfor -%}
200 {{ updated_hosts }}
201
202 - name: Create path to save tmp
203 ansible.builtin.set_fact:
204 file_path: "{{ temp_file_location }}/one_click_migration_{{ enclosure_serial_number_out }}"
205
206 - name: Ensure temporary folder exists
207 ansible.builtin.file:
208 path: "{{ file_path }}"
209 state: directory
210 mode: '0755'
211 delegate_to: localhost
212
213 - name: Find all files in the temporary folder
214 ansible.builtin.find:
215 paths: "{{ file_path }}"
216 register: temp_files
217 delegate_to: localhost
218
219 - name: Remove all files in the temporary folder
220 ansible.builtin.file:
221 path: "{{ item.path }}"
222 state: absent
223 loop: "{{ temp_files.files }}"
224
225 - name: Write extracted_hosts information to file.
226 ansible.builtin.copy:
227 content: "{{ extracted_hosts | to_nice_json }}"
228 dest: "{{ file_path }}/svc_host_obj_list_present.json"
229 mode: '0600'
230 delegate_to: localhost
231
232 - name: Call Host_identification playbook to fetch list of host mapped to flashsystem.
233 ansible.builtin.command:
234 cmd: >
235 ansible-playbook host_identification.yml
236 -i {{ inventory_file }}
237 -e 'file_name={{ file_path }}
238 json_file=svc_host_obj_list_present.json
239 location_flag=target'
240 changed_when: false
241
242 - name: Check if file directory exists
243 ansible.builtin.stat:
244 path: "{{ file_path }}/matched_hosts.json"
245 register: matched_host_dir
246
247 - name: End play if condition not met
248 ansible.builtin.meta: end_play
249 when: not matched_host_dir.stat.exists
250
251 - name: Read data provided by host_identification.yml playbook from file.
252 ansible.builtin.slurp:
253 src: "{{ file_path }}/matched_hosts.json"
254 register: host_matched_list
255 delegate_to: localhost
256
257 - name: Parse host_matched_list to read content.
258 ansible.builtin.set_fact:
259 host_matched_list_processed: "{{ host_matched_list['content'] | b64decode | from_json }}"
260
261 - name: Set facts for matched hosts and types
262 ansible.builtin.set_fact:
263 host_matched_inventory_hosts: "{{ host_matched_list_processed | map(attribute='inventory_hostname') | list }}"
264 host_matched_hosts_type: "{{ host_matched_list_processed | map(attribute='host_type') | list }}"
265 is_windows_host: "{{ 'Win32NT' in (host_matched_list_processed | map(attribute='host_type') | list) }}"
266 is_esxi_host: "{{ 'VMkernel' in (host_matched_list_processed | map(attribute='host_type') | list) }}"
267 extracted_hosts_length: "{{ extracted_hosts.keys() | length }}"
268
269 - name: Set single host flag for migration
270 ansible.builtin.set_fact:
271 single_host_present_flag: "{{ (extracted_hosts_length | int == 1 and deployment_type == 'single_host_migre') | bool }}"
272
273 - name: Is host are same from inventory and from svc host
274 when: deployment_type == "multi_host_migre"
275 block:
276
277 - name: Extract all inventory hosts list for inventory file
278 ansible.builtin.set_fact:
279 inventory_hosts: "{{ groups[hosts_name] | list }}"
280
281 - name: Extract host which are not present in inventory file
282 ansible.builtin.set_fact:
283 host_not_in_inventory: "{{ host_matched_inventory_hosts | intersect(inventory_hosts) }}"
284
285 - name: Extract length of host which are not present in inventory file
286 ansible.builtin.set_fact:
287 host_not_in_inventory_length: "{{ host_not_in_inventory | length }}"
288
289 - name: Set facts for flags
290 ansible.builtin.set_fact:
291 are_all_hosts_in_inventory: "{{ true if extracted_hosts_length == host_not_in_inventory_length else false }}"
292
293 - name: Print the matched hosts
294 ansible.builtin.debug:
295 msg: "Host assign to partition: {{ host_not_in_inventory }}"
296
297
298 ####################################
299 # Host rescan action
300 ####################################
301
302 - name: Host rescan action if host_rescan_requested event raised.
303 when: (lspartition_output | selectattr('user_action_type', 'equalto', 'host_rescan_requested') | list | length) > 0
304 block:
305
306 - name: Check extracted_hosts is empty.
307 when: extracted_hosts != []
308 block:
309
310 - name: Extract FC inventory hostname
311 ansible.builtin.set_fact:
312 fc_hosts: "{{ host_matched_list_processed | selectattr('connection', 'equalto', 'FC') | map(attribute='inventory_hostname') | list }}"
313
314 - name: Extract iSCSI inventory hostname
315 ansible.builtin.set_fact:
316 iscsi_hosts: "{{ host_matched_list_processed | selectattr('connection', 'equalto', 'iscsi') | map(attribute='inventory_hostname') | list }}"
317
318 - name: Call rescan playbook based on hosts discovery status.
319 ansible.builtin.command:
320 cmd: "ansible-playbook rescan_multipath_devices.yml -i {{ inventory_file }} -e 'file_name={{ file_path }}'"
321 changed_when: false
322 when: (lspartition_output | selectattr('hosts_discovery_status', 'equalto', 'need_rescan') | list | length) > 0 and fc_hosts | length != 0
323
324 - name: Call discovery playbook based on hosts discovery status.
325 ansible.builtin.command:
326 cmd: "ansible-playbook discover_multipath_devices.yml -i {{ inventory_file }} -e 'file_name={{ file_path }} rescan_flag=no'"
327 changed_when: false
328 when: (lspartition_output | selectattr('hosts_discovery_status', 'equalto', 'need_rescan') | list | length) > 0 and iscsi_hosts | length != 0
329
330 - name: Waiting for IO to stabilize.
331 ansible.builtin.wait_for:
332 timeout: "{{ io_stability_time | int }}"
333 when: (lspartition_output | selectattr('hosts_discovery_status', 'equalto', 'need_rescan') | list | length) > 0
334
335 - name: Run lspartition on flashsystem to verify the host discovery status.
336 ibm.storage_virtualize.ibm_svcinfo_command:
337 clustername: "{{ ansible_host }}"
338 username: "{{ ansible_user }}"
339 password: "{{ ansible_password }}"
340 command: "lspartition -gui -json {{ partition_name }}"
341 log_path: "{{ logpath }}"
342 register: partition_in_progress_info
343
344 - name: Clean the lspartition output.
345 ansible.builtin.set_fact:
346 partition_in_progress_info_output: "{{ (partition_in_progress_info.stdout | from_json) }}"
347
348 - name: Rescan triggered up to 5 times.
349 when: partition_in_progress_info_output['hosts_discovery_status'] != 'ready'
350 block:
351 - name: Read data provided by host_identification.yml playbook from file.
352 ansible.builtin.slurp:
353 src: "{{ file_path }}/matched_hosts.json"
354 register: host_matched_list
355 delegate_to: localhost
356
357 - name: Parse host_matched_list to read content.
358 ansible.builtin.set_fact:
359 host_matched_list_processed: "{{ host_matched_list['content'] | b64decode | from_json }}"
360
361 # running it for 5 times
362 - name: Check hosts_discovery_status and run rescan task 1.
363 ansible.builtin.import_tasks: test_and_rescan_hosts.yml
364
365 - name: Check hosts_discovery_status and run rescan task 2.
366 ansible.builtin.import_tasks: test_and_rescan_hosts.yml
367 when: partition_in_progress_info_output_1['hosts_discovery_status'] != 'ready'
368
369 - name: Check hosts_discovery_status and run rescan task 3.
370 ansible.builtin.import_tasks: test_and_rescan_hosts.yml
371 when: partition_in_progress_info_output_1['hosts_discovery_status'] != 'ready'
372
373 - name: Check hosts_discovery_status and run rescan task 4.
374 ansible.builtin.import_tasks: test_and_rescan_hosts.yml
375 when: partition_in_progress_info_output_1['hosts_discovery_status'] != 'ready'
376
377 - name: Check hosts_discovery_status and run rescan task 5.
378 ansible.builtin.import_tasks: test_and_rescan_hosts.yml
379 when: partition_in_progress_info_output_1['hosts_discovery_status'] != 'ready'
380
381 - name: Fix the host rescan request event (host_rescan_requested) if hosts discovery status is ready.
382 ibm.storage_virtualize.ibm_sv_manage_storage_partition:
383 clustername: "{{ ansible_host }}"
384 username: "{{ ansible_user }}"
385 password: "{{ ansible_password }}"
386 name: "{{ partition_name }}"
387 migrationaction: fixeventwithchecks
388 state: present
389 log_path: "{{ logpath }}"
390 when: partition_in_progress_info_output['hosts_discovery_status'] == 'ready'
391
392
393 ####################################
394 # Commit migrating action
395 ####################################
396
397 - name: Commit migrating when commit_or_rollback event raised.
398 when: (lspartition_output | selectattr('user_action_type', 'equalto', 'commit_or_rollback') | list | length) > 0
399 block:
400
401 - name: Validate multipath on target system.
402 when: extracted_hosts != [] and min_active_path != 0 and not is_windows_host and not is_esxi_host
403 block:
404
405 - name: Fetch WWNN for Target system.
406 ibm.storage_virtualize.ibm_svc_info:
407 gather_subset: "node"
408 clustername: "{{ ansible_host }}"
409 username: "{{ ansible_user }}"
410 password: "{{ ansible_password }}"
411 log_path: "{{ logpath }}"
412 register: targetportfc_tgt
413
414 - name: Set fact for lsnode for Target system.
415 ansible.builtin.set_fact:
416 targetports_data_tgt: "{{ targetportfc_tgt.Node }}"
417
418 - name: Initialize empty dictionary for Target system.
419 ansible.builtin.set_fact:
420 targetports_output_tgt: {}
421
422 - name: Extract relevant data for Target system.
423 ansible.builtin.set_fact:
424 targetports_output_tgt: >-
425 {{
426 targetports_output_tgt | combine({
427 item.id | int: {
428 "name": item.name,
429 "WWNN": item.WWNN,
430 "iscsi_name": item.iscsi_name,
431 }
432 })
433 }}
434 loop: "{{ targetports_data_tgt }}"
435 when: item is not none
436
437 - name: Write extracted data to file to send to verify_multipath_devices playbook.
438 delegate_to: localhost
439 ansible.builtin.copy:
440 content: "{{ targetports_output_tgt | to_nice_json }}"
441 dest: "{{ file_path }}/vmd_output.json"
442 mode: '0600'
443
444 - name: Call verify multipath devices playbook.
445 ansible.builtin.command:
446 cmd: "ansible-playbook verify_multipath_devices.yml -i {{ inventory_file }} -e 'file_name={{ file_path }}'"
447 changed_when: false
448
449 - name: Read output data generated by verify_multipath_devices playbook.
450 ansible.builtin.slurp:
451 src: "{{ file_path }}/vmd_output_final_out.json"
452 register: json_data
453
454 - name: Parse JSON.
455 ansible.builtin.set_fact:
456 parsed_data: "{{ json_data['content'] | b64decode | from_json }}"
457
458 - name: Set commit flag based on min_active_path.
459 ansible.builtin.set_fact:
460 non_compliant_names: "{{ parsed_data['data'] | selectattr('non_compliant_devices', 'ne', []) |
461 map(attribute='active_paths_on_tgt.inventory_name') | list }}"
462
463 - name: Set commit flag based on min_active_path.
464 ansible.builtin.set_fact:
465 commit_flag: false
466 when: non_compliant_names | length > 0
467
468 - name: Print non-compliant inventory names.
469 ansible.builtin.debug:
470 msg: "{{ non_compliant_names | map('regex_replace', '^(.*)$', '\\1 does not meet the requirement') | list }}"
471 when: non_compliant_names | length > 0
472
473 - name: Over write the single_host_present_flag flag if deployment_type is multi_host_migre
474 ansible.builtin.set_fact:
475 single_host_present_flag: true
476 when: deployment_type == "multi_host_migre"
477
478 - name: Print commit flags.
479 ansible.builtin.debug:
480 msg:
481 - "commit_flag is set to {{ commit_flag }}"
482 - "are_all_hosts_in_inventory {{ are_all_hosts_in_inventory }}"
483 - "single_host_present_flag {{ single_host_present_flag }}"
484 - "extracted_hosts_length {{ extracted_hosts_length }}"
485 - "deployment_type {{ deployment_type }}"
486
487 - name: Commit and logout block
488 when: commit_flag and are_all_hosts_in_inventory and single_host_present_flag
489 block:
490
491 - name: Set facts for partition name.
492 ansible.builtin.set_fact:
493 partition_name: "{{ migrating_partition[0]['name'] }}"
494
495 - name: Run lspartition on flashsystem to source cluster information.
496 ibm.storage_virtualize.ibm_svcinfo_command:
497 clustername: "{{ ansible_host }}"
498 username: "{{ ansible_user }}"
499 password: "{{ ansible_password }}"
500 command: "lspartition -gui -json {{ partition_name }}"
501 log_path: "{{ logpath }}"
502 register: partition_in_progress_info
503
504 - name: Clean the lspartition output.
505 ansible.builtin.set_fact:
506 partition_in_progress_info_output: "{{ (partition_in_progress_info.stdout | from_json) }}"
507
508 - name: Fetch cluster IP for source system.
509 ibm.storage_virtualize.ibm_svc_info:
510 gather_subset: "partnership"
511 clustername: "{{ ansible_host }}"
512 username: "{{ ansible_user }}"
513 password: "{{ ansible_password }}"
514 objectname: "{{ partition_in_progress_info_output['location1_system_id'] }}"
515 log_path: "{{ logpath }}"
516 register: partnership_info
517
518 - name: Cleaning up ip addr
519 ansible.builtin.set_fact:
520 ip_only: "{{ partnership_info.Partnership['console_IP'].split(':')[0] }}"
521
522 - name: Find matching hostname for the user-provided IP # # noqa run-once[task]
523 ansible.builtin.set_fact:
524 matched_host: "{{ item }}"
525 loop: "{{ groups['flash_systems'] }}"
526 when: hostvars[item].ansible_host == ip_only
527 run_once: true
528
529 - name: Source side ip logout block
530 when: matched_host is defined and matched_host | length != 0
531 block:
532
533 - name: Setting up source credential
534 ansible.builtin.set_fact:
535 source_ansible_host: "{{ hostvars[matched_host]['ansible_host'] }}"
536 source_ansible_user: "{{ hostvars[matched_host]['ansible_user'] }}"
537 source_ansible_password: "{{ hostvars[matched_host]['ansible_password'] }}"
538 delegate_to: "{{ matched_host | default('localhost') }}"
539
540 - name: Setting up source credential safely
541 ansible.builtin.set_fact:
542 source_ansible_host: "{{ hostvars[matched_host | default('')]['ansible_host'] | default('') }}"
543 source_ansible_user: "{{ hostvars[matched_host | default('')]['ansible_user'] | default('') }}"
544 source_ansible_password: "{{ hostvars[matched_host | default('')]['ansible_password'] | default('') }}"
545 when: matched_host is defined and matched_host in hostvars
546
547 - name: Gather lshost information from flashsystem.
548 ibm.storage_virtualize.ibm_svc_info:
549 clustername: "{{ source_ansible_host }}"
550 username: "{{ source_ansible_user }}"
551 password: "{{ source_ansible_password }}"
552 log_path: "{{ logpath }}"
553 gather_subset: "host"
554 filtervalue: 'partition_name={{ partition_name }}'
555 register: lshost_output
556 changed_when: false
557
558 - name: Gather details of each host on flashsystem.
559 ibm.storage_virtualize.ibm_svc_info:
560 gather_subset: "host"
561 clustername: "{{ source_ansible_host }}"
562 username: "{{ source_ansible_user }}"
563 password: "{{ source_ansible_password }}"
564 objectname: "{{ item.id }}"
565 log_path: "{{ logpath }}"
566 changed_when: false
567 register: shared_targetports_output
568 loop: "{{ lshost_output.Host }}"
569
570 - name: Initialize extracted_hosts_form_source list.
571 ansible.builtin.set_fact:
572 extracted_hosts_form_source: {}
573 extracted_hosts_form_source_tmp: []
574
575 - name: Extract relevant iscsi host data for the identified partition for extracted_hosts_form_source.
576 ansible.builtin.set_fact:
577 extracted_hosts_form_source: >-
578 {{
579 extracted_hosts_form_source | combine({
580 item.Host.id | int: {
581 "inventory_hostname": inventory_hostname,
582 "name": item.Host.name,
583 "iscsi_name": item.Host.nodes | default([]) | map(attribute='iscsi_name') | list,
584 "partition": item.Host.partition_name | default(""),
585 "portset_name":item.Host.portset_name,
586 "type": 'iscsi'
587 }
588 })
589 }}
590 loop: "{{ shared_targetports_output.results }}"
591 when: item.Host is not none and item.Host.nodes[0].iscsi_name is defined
592
593 - name: Process extracted host data if not empty.
594 when: extracted_hosts_form_source | length != 0
595 block:
596
597 - name: Gather lsportset information from flashsystem.
598 ibm.storage_virtualize.ibm_svc_info:
599 gather_subset: "portset"
600 clustername: "{{ source_ansible_host }}"
601 username: "{{ source_ansible_user }}"
602 password: "{{ source_ansible_password }}"
603 objectname: "{{ item.value.portset_name }}"
604 log_path: "{{ logpath }}"
605 changed_when: false
606 register: portset_info
607 loop: "{{ extracted_hosts_form_source | dict2items }}"
608 when: item.value.type == 'iscsi'
609
610 - name: Build host entries for extracted_hosts_form_source
611 ansible.builtin.set_fact:
612 extracted_hosts_form_source_tmp: >-
613 {{
614 extracted_hosts_form_source_tmp | default([]) + [
615 {
616 (item.item.key | string): (
617 item.item.value | combine(
618 (
619 {'replication_portset_link_uid': item.Portset.replication_portset_link_uid}
620 if item.item.value.type == 'iscsi'
621 else {}
622 )
623 )
624 )
625 }
626 ]
627 }}
628 loop: "{{ portset_info.results }}"
629 when: item.item is defined and item.item.value is defined
630
631 - name: Combine extracted_hosts_form_source into a single dict
632 ansible.builtin.set_fact:
633 extracted_hosts_form_source: "{{ extracted_hosts_form_source_tmp | default([]) | combine }}"
634
635 - name: Gather lsip information from flashsystem.
636 ibm.storage_virtualize.ibm_svcinfo_command:
637 clustername: "{{ source_ansible_host }}"
638 username: "{{ source_ansible_user }}"
639 password: "{{ source_ansible_password }}"
640 command: "lsip -json"
641 log_path: "{{ logpath }}"
642 register: ip_info
643
644 - name: Convert raw ip_info.stdout string to structured data
645 ansible.builtin.set_fact:
646 ip_info_parsed: "{{ ip_info.stdout | from_json }}"
647
648 - name: Add iscsi_ips to extracted_hosts
649 ansible.builtin.set_fact:
650 extracted_hosts_form_source: >-
651 {%- set updated_hosts = {} -%}
652 {%- for key, host in extracted_hosts_form_source .items() -%}
653 {%- set _host = host.copy() -%}
654 {%- if 'type' in _host and _host['type'] == 'iscsi' and 'portset_name' in _host -%}
655 {%- set ips = [] -%}
656 {%- for ip in ip_info_parsed -%}
657 {%- if 'portset_name' in ip and
658 (ip['portset_name'] | string | lower | trim) == (_host['portset_name'] | string | lower | trim) and
659 'IP_address' in ip -%}
660 {%- set _ = ips.append(ip['IP_address']) -%}
661 {%- endif -%}
662 {%- endfor -%}
663 {%- set _ = _host.update({'iscsi_ips': ips}) -%}
664 {%- endif -%}
665 {%- set _ = updated_hosts.update({ key: _host }) -%}
666 {%- endfor -%}
667 {{ updated_hosts }}
668
669 - name: Write extracted_hosts_form_source information to file.
670 ansible.builtin.copy:
671 content: "{{ extracted_hosts_form_source | to_nice_json }}"
672 dest: "{{ file_path }}/svc_host_obj_list_present_source.json"
673 mode: '0600'
674 delegate_to: localhost
675
676 - name: Call Host_identification playbook to fetch list of host mapped to flashsystem.
677 ansible.builtin.command:
678 cmd: >
679 ansible-playbook host_identification.yml
680 -i {{ inventory_file }}
681 -e 'file_name={{ file_path }}
682 json_file=svc_host_obj_list_present_source.json
683 location_flag=source'
684 changed_when: false
685
686 - name: Complete migration (on target system) by running migration action.
687 ibm.storage_virtualize.ibm_sv_manage_storage_partition:
688 clustername: "{{ ansible_host }}"
689 username: "{{ ansible_user }}"
690 password: "{{ ansible_password }}"
691 name: "{{ partition_name }}"
692 migrationaction: fixeventwithchecks
693 state: present
694 log_path: "{{ logpath }}"
695 when: matched_host is defined and matched_host | length != 0
696
697 - name: Wait for either migration_status = "" to complete the migration
698 ibm.storage_virtualize.ibm_svc_info:
699 clustername: "{{ ansible_host }}"
700 username: "{{ ansible_user }}"
701 password: "{{ ansible_password }}"
702 gather_subset: partition
703 objectname: "{{ partition_name }}"
704 register: lspartition_out
705 until: lspartition_out.Partition['migration_status'] == ''
706 retries: 60
707 delay: 30
708
709 - name: Call iscsi_logout playbook to logout
710 ansible.builtin.command:
711 cmd: "ansible-playbook iscsi_logout.yml -i {{ inventory_file }} -e 'file_name={{ file_path }}'"
712 changed_when: false
713 when:
714 - matched_host is defined
715 - matched_host | length > 0
716 - extracted_hosts_form_source is defined
717 - extracted_hosts_form_source | length > 0