|
95 | 95 | az disk show --name {{ item }} \ |
96 | 96 | --subscription {{ compute_metadata.json.compute.subscriptionId }} \ |
97 | 97 | --resource-group {{ compute_metadata.json.compute.resourceGroupName }} \ |
98 | | - --query "{name:name, sku:sku.name, size:sizeGb, encryption:encryption.type, iops:diskIOPSReadWrite, mbps:diskMBpsReadWrite, size:diskSizeGB}" --output json |
| 98 | + --query "{name:name, sku:sku.name, size:sizeGb, encryption:encryption.type, iops:diskIOPSReadWrite, mbps:diskMBpsReadWrite, size:diskSizeGB, tier:tier}" --output json |
99 | 99 |
|
100 | 100 | - name: Debug azure disks data collected |
101 | 101 | when: azure_disks_metadata_results is defined |
102 | 102 | ansible.builtin.debug: |
103 | 103 | var: azure_disks_metadata_results |
104 | 104 | verbosity: 1 |
105 | 105 |
|
| 106 | + - name: Check if any NFS filesystem is mounted |
| 107 | + ansible.builtin.set_fact: |
| 108 | + has_nfs_mounts: "{{ mount_info.stdout_lines | select('search', '\\snfs[34]?\\s') | list | length > 0 }}" |
| 109 | + |
| 110 | + - name: Check for ANF usage in mount_info, looking for IP addresses |
| 111 | + when: has_nfs_mounts | bool |
| 112 | + ansible.builtin.set_fact: |
| 113 | + anf_ip_addresses: "{{ mount_info.stdout_lines |
| 114 | + | map('split', ' ') |
| 115 | + | map('list') |
| 116 | + | selectattr('1', 'defined') |
| 117 | + | map(attribute='1') |
| 118 | + | select('match', '^(\\d{1,3}\\.){3}\\d{1,3}:') |
| 119 | + | map('regex_replace', '^((\\d{1,3}\\.){3}\\d{1,3}):.*', '\\1') |
| 120 | + | list |
| 121 | + | unique }}" |
| 122 | + - name: Debug ANF IP addresses found |
| 123 | + when: anf_ip_addresses is defined |
| 124 | + ansible.builtin.debug: |
| 125 | + var: anf_ip_addresses |
| 126 | + |
| 127 | + - name: Check for AFS usage in mount_info, looking for storage account names |
| 128 | + when: has_nfs_mounts | bool |
| 129 | + ansible.builtin.set_fact: |
| 130 | + afs_storage_accounts: "{{ mount_info.stdout_lines |
| 131 | + | map('split', ' ') |
| 132 | + | map(attribute='1') |
| 133 | + | select('search', '\\.file\\.core\\.windows\\.net:/') |
| 134 | + | map('regex_replace', '^.*:/([^/]+)/.*', '\\1') |
| 135 | + | list |
| 136 | + | unique }}" |
| 137 | + |
| 138 | + - name: Debug AFS storage account names found |
| 139 | + when: afs_storage_accounts is defined |
| 140 | + ansible.builtin.debug: |
| 141 | + var: afs_storage_accounts |
| 142 | + |
106 | 143 | - name: Collect ANF storage data if NFS is used |
107 | 144 | when: |
| 145 | + - has_nfs_mounts | bool |
108 | 146 | - NFS_provider is defined |
109 | 147 | - "'ANF' in NFS_provider" |
110 | 148 | - ANF_account_rg is defined |
|
155 | 193 |
|
156 | 194 | - name: Collect AFS storage data if NFS is used |
157 | 195 | when: |
| 196 | + - has_nfs_mounts | bool |
158 | 197 | - NFS_provider is defined |
159 | 198 | - "'AFS' in NFS_provider" |
| 199 | + - afs_storage_accounts is defined |
| 200 | + - afs_storage_accounts | length > 0 |
160 | 201 | register: afs_storage_metadata_results |
161 | 202 | delegate_to: localhost |
162 | 203 | ansible.builtin.shell: |
163 | 204 | executable: /bin/bash |
164 | 205 | cmd: | |
165 | 206 | set -o pipefail |
166 | | - for sa in $(az storage account list \ |
167 | | - --query "[?kind=='FileStorage'].{rg:resourceGroup,name:name,id:id}" \ |
168 | | - -o tsv | awk '{print $1":"$2":"$3}'); do rg=$(echo $sa | cut -d: -f1); \ |
169 | | - acc=$(echo $sa | cut -d: -f2); sid=$(echo $sa | cut -d: -f3); \ |
170 | | - dns="$acc.file.core.windows.net"; for sh in $(az storage share-rm list --resource-group $rg --storage-account $acc \ |
171 | | - --query "[?enabledProtocols=='NFS'].[name,accessTier,quotaGiB]" -o tsv); \ |
172 | | - do name=$(echo $sh | awk '{print $1}'); tier=$(echo $sh | awk '{print $2}'); \ |
173 | | - quota=$(echo $sh | awk '{print $3}'); \ |
174 | | - peip=$(az network private-endpoint list \ |
175 | | - --query "[?privateLinkServiceConnections[?privateLinkServiceId=='$sid']].customDnsConfigs[].ipAddresses[]" -o tsv); \ |
176 | | - for ip in $peip; do thr=$((100 + ( (quota*4+99)/100 ) + ( (quota*6+99)/100 ) )); \ |
177 | | - iops=$((quota+3000)); \ |
178 | | - if [ $iops -gt 100000 ]; then iops=100000; fi; \ |
179 | | - echo "{\"Type\":\"AFS\",\"Name\":\"$name\",\"Pool\":\"$acc\",\"ServiceLevel\":\"$tier\",\"ThroughputMibps\":$thr,\"ProtocolTypes\":\"NFS4.1\",\"NFSAddressDNS\":\"$dns:/$acc/$name\",\"NFSAddress\":\"$ip:/$acc/$name\",\"QoSType\":\"Manual\",\"IOPS\":$iops,\"Id\":\"$sid\"}"; \ |
180 | | - done; done; done |
| 207 | + for acc in {{ afs_storage_accounts | join(' ') }}; do |
| 208 | + sa_info=$(az storage account show --name "$acc" --query "{rg:resourceGroup,name:name,id:id}" -o tsv) |
| 209 | + rg=$(echo "$sa_info" | awk '{print $1}') |
| 210 | + sid=$(echo "$sa_info" | awk '{print $3}') |
| 211 | + dns="$acc.file.core.windows.net" |
| 212 | + for sh in $(az storage share-rm list --resource-group "$rg" --storage-account "$acc" \ |
| 213 | + --query "[?enabledProtocols=='NFS'].[name,accessTier,quotaGiB]" -o tsv); do |
| 214 | + name=$(echo "$sh" | awk '{print $1}') |
| 215 | + tier=$(echo "$sh" | awk '{print $2}') |
| 216 | + quota=$(echo "$sh" | awk '{print $3}') |
| 217 | + peip=$(az network private-endpoint list \ |
| 218 | + --query "[?privateLinkServiceConnections[?privateLinkServiceId=='$sid']].customDnsConfigs[].ipAddresses[]" -o tsv) |
| 219 | + for ip in $peip; do |
| 220 | + thr=$((100 + ( (quota*4+99)/100 ) + ( (quota*6+99)/100 ) )) |
| 221 | + iops=$((quota+3000)) |
| 222 | + if [ $iops -gt 100000 ]; then iops=100000; fi |
| 223 | + echo "{\"Type\":\"AFS\",\"Name\":\"$name\",\"Pool\":\"$acc\",\"ServiceLevel\":\"$tier\",\"ThroughputMibps\":$thr,\"ProtocolTypes\":\"NFS4.1\",\"NFSAddressDNS\":\"$dns:/$acc/$name\",\"NFSAddress\":\"$ip:/$acc/$name\",\"QoSType\":\"Manual\",\"IOPS\":$iops,\"Id\":\"$sid\"}" |
| 224 | + done |
| 225 | + done |
| 226 | + done |
181 | 227 |
|
182 | 228 | - name: Debug AFS storage data collected |
183 | 229 | when: afs_storage_metadata_results is defined |
|
0 commit comments