|
9 | 9 | - name: SAP Storage Setup - Make a list of unused disk devices of the requested sizes
|
10 | 10 | ansible.builtin.set_fact:
|
11 | 11 | available_devices: |
|
12 |
| - {% set av_disks = [] %} |
13 |
| - {% set all_disks = (ansible_devices | dict2items) %} |
14 |
| - {% for disk in all_disks %} |
15 |
| - {%- for fs in sap_storage_setup_new_mounts_fact %} |
| 12 | + {%- set av_disks = [] -%} |
| 13 | + {%- set all_disks = (ansible_devices | dict2items) -%} |
| 14 | + {%- for disk in all_disks -%} |
| 15 | + {%- for fs in sap_storage_setup_new_mounts_fact -%} |
| 16 | + {%- if disk.value.size | regex_search('.*TB$') -%} |
| 17 | + {%- set disk_size_gb = (((( disk.value.size | replace(' TB','') | float * 1024) /8) | round(0,'ceil') * 8) | int) -%} |
| 18 | + {%- else -%} |
| 19 | + {%- set disk_size_gb = (disk.value.size | regex_replace('(\.\d+\s*)', '') | replace('GB','') | int) -%} |
| 20 | + {%- endif -%} |
16 | 21 | {%- if not disk.key.startswith('dm-')
|
17 | 22 | and disk.value.links.uuids | length == 0
|
18 | 23 | and disk.value.partitions | length == 0
|
19 | 24 | and fs.disk_size is defined
|
20 |
| - and (fs.disk_size | string + 'GB') in (disk.value.size | regex_replace('(\.\d+\s*)', '')) %} |
21 |
| - {%- set add_to_list = av_disks.append(disk) %} |
22 |
| - {%- endif %} |
23 |
| - {%- endfor %} |
24 |
| - {%- endfor %} |
| 25 | + and ((disk_size_gb-8) <= fs.disk_size <= (disk_size_gb+8)) -%} |
| 26 | + {%- set add_to_list = av_disks.append(disk) -%} |
| 27 | + {%- endif -%} |
| 28 | + {%- endfor -%} |
| 29 | + {%- endfor -%} |
25 | 30 | {{ av_disks | items2dict }}
|
26 | 31 |
|
27 | 32 | # !!
|
28 | 33 | # If the DISK MATCHING syntax has changed in the above, it must also
|
29 |
| -# be adjusted in the next task |
| 34 | +# be adjusted in the next task. |
| 35 | +# As ansible_devices returns only human-readable format, handling |
| 36 | +# for TB is provided and default is GB; use of MB and PB will error. |
30 | 37 | # !!
|
31 | 38 |
|
32 | 39 | ##########
|
|
60 | 67 | -%}
|
61 | 68 |
|
62 | 69 | {%- for dev in av_dev -%}
|
63 |
| - {%- if (fs.disk_size | string + 'GB') in (dev.value.size | regex_replace('(\.\d+\s*)', '')) |
| 70 | +
|
| 71 | + {%- if dev.value.size | regex_search('.*TB$') -%} |
| 72 | + {% set disk_size_gb = (((( dev.value.size | replace(' TB','') | float * 1024) /8) | round(0,'ceil') * 8) | int) -%} |
| 73 | + {%- else -%} |
| 74 | + {% set disk_size_gb = (dev.value.size | regex_replace('(\.\d+\s*)', '') | replace('GB','') | int) -%} |
| 75 | + {%- endif -%} |
| 76 | + {%- if (disk_size_gb-8) <= fs.disk_size <= (disk_size_gb+8) |
64 | 77 | and dev.key not in assigned_dev
|
65 | 78 | and dev.value.holders | length == 0
|
66 |
| - and matching_dev | length < (fs.lvm_lv_stripes | d('1') | int) %} |
| 79 | + and matching_dev | length < (fs.lvm_lv_stripes | d('1') | int) -%} |
67 | 80 |
|
68 |
| - {%- set assigned = assigned_dev.append(dev.key) %} |
69 |
| - {%- set add = matching_dev.append('/dev/' + dev.key) %} |
| 81 | + {%- set assigned = assigned_dev.append(dev.key) -%} |
| 82 | + {%- set add = matching_dev.append('/dev/' + dev.key) -%} |
| 83 | + {%- endif -%} |
70 | 84 |
|
71 |
| - {%- endif %} |
72 |
| - {%- endfor %} |
| 85 | + {%- endfor -%} |
73 | 86 |
|
74 | 87 | {%- if matching_dev | length > 0 -%}
|
75 | 88 | {%- set extend = device_map.extend([
|
|
80 | 93 | 'name': fs.name,
|
81 | 94 | 'size': fs.disk_size,
|
82 | 95 | }
|
83 |
| - ]) %} |
84 |
| - {%- endif %} |
85 |
| - {%- endif %} |
86 |
| - {%- endfor %} |
| 96 | + ]) -%} |
| 97 | + {%- endif -%} |
| 98 | + {%- endif -%} |
| 99 | + {%- endfor -%} |
87 | 100 | {{ device_map }}
|
88 | 101 |
|
89 | 102 |
|
|
0 commit comments