|
32 | 32 | # - mount_src: /my_dir/usr/sap/DB1/ASCS00 |
33 | 33 | # mountpoint: /usr/sap/DB1/ASCS00 |
34 | 34 |
|
| 35 | +# This task creates list of mount points and related directories to be created on the NFS share. |
| 36 | +# Generic mount point elif also covers SAP specific mount points: '/usr/sap/trans', '/hana/*', '/lss/shared'. |
| 37 | +# Resulting list length can be: |
| 38 | +# - 0 if mount point is in the forbidden paths list. |
| 39 | +# - 1 if a valid mount point was defined, SAP or non-SAP specific. |
| 40 | +# - 1+ if /usr/sap was defined and multiple subdirectories were created based on the host type. |
35 | 41 | - name: SAP Storage Setup - ({{ nfs_item.name }}) Set fact for directories |
36 | 42 | ansible.builtin.set_fact: |
37 | 43 | __sap_storage_setup_fact_related_directories: | |
38 | 44 | {% set mount_list = [] %} |
| 45 | + {%- set clean_mount_src = nfs_item.nfs_path | regex_replace('/$', '') -%} |
| 46 | + {%- set clean_mountpoint = nfs_item.mountpoint | regex_replace('/$', '') -%} |
39 | 47 |
|
40 | | - {%- if nfs_item.mountpoint | regex_replace('/$', '') == '/sapmnt' -%} |
| 48 | + {%- if clean_mountpoint == '/sapmnt' -%} |
41 | 49 | {%- set add_sapmnt = mount_list.extend([ |
42 | 50 | { |
43 | | - 'mount_src': nfs_item.nfs_path | regex_replace('/$', ''), |
44 | | - 'mountpoint': nfs_item.mountpoint | regex_replace('/$', ''), |
| 51 | + 'mount_src': clean_mount_src, |
| 52 | + 'mountpoint': clean_mountpoint, |
45 | 53 | 'dir_only': '/' + sap_storage_setup_sid, |
46 | 54 | } |
47 | 55 | ]) %} |
48 | 56 |
|
49 | | - {%- elif nfs_item.mountpoint | regex_replace('/$', '') == '/usr/sap/trans' %} |
50 | | - {%- set add_trans = mount_list.extend([ |
51 | | - { |
52 | | - 'mount_src': nfs_item.nfs_path | regex_replace('/$', ''), |
53 | | - 'mountpoint': nfs_item.mountpoint | regex_replace('/$', ''), |
54 | | - } |
55 | | - ]) %} |
56 | | -
|
57 | | - {%- elif nfs_item.mountpoint | regex_replace('/$', '') == '/usr/sap' -%} |
| 57 | + {%- elif clean_mountpoint == '/usr/sap' -%} |
58 | 58 | {%- for common in sap_storage_setup_nfs_dirs_usr_sap.all %} |
59 | 59 | {%- set add_all_usrsap = mount_list.extend([ |
60 | 60 | { |
61 | | - 'mount_src': nfs_item.nfs_path | regex_replace('/$', '') + '/' + common, |
62 | | - 'mountpoint': nfs_item.mountpoint | regex_replace('/$', '') + '/' + common, |
| 61 | + 'mount_src': clean_mount_src + '/' + common, |
| 62 | + 'mountpoint': clean_mountpoint + '/' + common, |
63 | 63 | } |
64 | 64 | ]) %} |
65 | 65 | {%- endfor %} |
66 | 66 |
|
67 | 67 | {%- for type in host_type %} |
68 | | - {%- for dir in sap_storage_setup_nfs_dirs_usr_sap[type] %} |
| 68 | + {%- for dir in sap_storage_setup_nfs_dirs_usr_sap[type] | d([]) %} |
69 | 69 | {%- set dirs = mount_list.extend([ |
70 | 70 | { |
71 | | - 'mount_src': nfs_item.nfs_path | regex_replace('/$', '') + '/' + dir, |
72 | | - 'mountpoint': nfs_item.mountpoint | regex_replace('/$', '') + '/' + dir, |
| 71 | + 'mount_src': clean_mount_src + '/' + dir, |
| 72 | + 'mountpoint': clean_mountpoint + '/' + dir, |
73 | 73 | } |
74 | 74 | ]) %} |
75 | 75 | {%- endfor %} |
76 | 76 | {%- endfor %} |
77 | 77 |
|
78 | | - {%- elif nfs_item.mountpoint.startswith('/hana/') %} |
79 | | - {%- set add_hana = mount_list.extend([ |
80 | | - { |
81 | | - 'mount_src': nfs_item.nfs_path | regex_replace('/$', ''), |
82 | | - 'mountpoint': nfs_item.mountpoint | regex_replace('/$', ''), |
83 | | - } |
84 | | - ]) %} |
85 | | -
|
86 | | - {%- elif nfs_item.mountpoint | regex_replace('/$', '') == '/software' -%} |
87 | | - {%- set add_software = mount_list.extend([ |
| 78 | + {%- elif clean_mountpoint not in __sap_storage_setup_nfs_forbidden_paths -%} |
| 79 | + {%- set add_other_nfs = mount_list.extend([ |
88 | 80 | { |
89 | | - 'mount_src': nfs_item.nfs_path | regex_replace('/$', ''), |
90 | | - 'mountpoint': nfs_item.mountpoint | regex_replace('/$', ''), |
| 81 | + 'mount_src': clean_mount_src, |
| 82 | + 'mountpoint': clean_mountpoint, |
91 | 83 | } |
92 | 84 | ]) %} |
93 | 85 |
|
|
106 | 98 | {%- endif %} |
107 | 99 |
|
108 | 100 |
|
| 101 | +- name: SAP Storage Setup - Inform that no valid mount points were found |
| 102 | + ansible.builtin.debug: |
| 103 | + msg: > |
| 104 | + WARN: Provided NFS mount point '{{ nfs_item.mountpoint }}' will be skipped, because it is in the forbidden paths list: |
| 105 | + {{ __sap_storage_setup_nfs_forbidden_paths | map('quote') | join(', ') }}. |
| 106 | + when: |
| 107 | + # Only run this if the list is empty. |
| 108 | + - __sap_storage_setup_fact_related_directories | length == 0 |
| 109 | + |
| 110 | + |
| 111 | +- name: SAP Storage Setup - Inform that non-SAP mount points were found |
| 112 | + ansible.builtin.debug: |
| 113 | + msg: | |
| 114 | + INFO: Non-SAP specific mount point was detected: {{ __non_sap_mounts[0] }} |
| 115 | + The mount point will be mounted, but no SAP specific subdirectories will be created. |
| 116 | + vars: |
| 117 | + # List of expected SAP mounts based on task above. |
| 118 | + __sap_mount_regex: "^(/sapmnt|/usr/sap/trans|/lss/shared|/hana/.*|/software)$" |
| 119 | + |
| 120 | + __non_sap_mounts: >- |
| 121 | + {{ __sap_storage_setup_fact_related_directories |
| 122 | + | rejectattr('mountpoint', 'search', __sap_mount_regex) |
| 123 | + | map(attribute='mountpoint') |
| 124 | + | list }} |
| 125 | + when: |
| 126 | + # Only run this if the list wasn't expanded (ignoring the complex /usr/sap logic) |
| 127 | + - __sap_storage_setup_fact_related_directories | length == 1 |
| 128 | + - __non_sap_mounts | length > 0 |
| 129 | + |
| 130 | + |
109 | 131 | # Put temporary tasks inside a block which will make sure |
110 | 132 | # that even in case of failure the temporary mountpoint will be removed |
111 | 133 | - name: SAP Storage Setup - Temporary steps for NFS directory structure |
112 | 134 | ### Block global parameters |
113 | 135 | # Stop execution of tasks after this block for any host, if one host |
114 | 136 | # failed a task in this block. |
115 | 137 | any_errors_fatal: true |
| 138 | + # Don't execute temporary mount tasks if there is no valid NFS mount point. |
| 139 | + when: __sap_storage_setup_fact_related_directories | length > 0 |
116 | 140 | block: |
117 | 141 |
|
118 | 142 | - name: SAP Storage Setup - ({{ nfs_item.name }}) Create directory as temporary mountpoint |
|
0 commit comments