|
195 | 195 | when: |
196 | 196 | - has_nfs_mounts | bool |
197 | 197 | - NFS_provider is defined |
198 | | - - "'AFS' in NFS_provider" |
| 198 | + - NFS_provider == "AFS" |
199 | 199 | - afs_storage_accounts is defined |
200 | 200 | - afs_storage_accounts | length > 0 |
201 | 201 | register: afs_storage_metadata_results |
202 | 202 | delegate_to: localhost |
| 203 | + vars: |
| 204 | + accounts_list: "{{ afs_storage_accounts | join(' ') }}" |
203 | 205 | ansible.builtin.shell: |
204 | 206 | executable: /bin/bash |
205 | 207 | cmd: | |
| 208 | + #!/bin/bash |
206 | 209 | set -o pipefail |
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) |
| 210 | + for acc in {{ accounts_list }}; do |
| 211 | + sa_info=$(az storage account show --name "$acc" --query "{rg:resourceGroup,name:name,id:id}" -o tsv 2>&1) |
| 212 | + if [ $? -ne 0 ] || [ -z "$sa_info" ]; then |
| 213 | + echo "Error: Failed to retrieve storage account info for $acc: $sa_info" >&2 |
| 214 | + continue |
| 215 | + fi |
209 | 216 | rg=$(echo "$sa_info" | awk '{print $1}') |
210 | 217 | 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 |
| 218 | + dns="$acc.privatelink.file.core.windows.net" |
| 219 | + share_list=$(az storage share-rm list --resource-group "$rg" --storage-account "$acc" \ |
| 220 | + --query "[?enabledProtocols=='NFS'].[name,accessTier,shareQuota]" -o tsv 2>&1) |
| 221 | + if [ $? -ne 0 ]; then |
| 222 | + echo "Error: Failed to list shares for storage account $acc: $share_list" >&2 |
| 223 | + continue |
| 224 | + fi |
| 225 | + echo "$share_list" | \ |
| 226 | + while IFS=$'\t' read -r name tier quota; do |
| 227 | + if [ -z "$name" ]; then |
| 228 | + continue |
| 229 | + fi |
| 230 | + thr=$((100 + ( (quota*4+99)/100 ) + ( (quota*6+99)/100 ) )) |
| 231 | + iops=$((quota+3000)) |
| 232 | + if [ $iops -gt 100000 ]; then iops=100000; fi |
| 233 | + echo "{\"Type\":\"AFS\",\"Name\":\"$name\",\"Pool\":\"$acc\",\"ServiceLevel\":\"$tier\",\"Quota\":\"$quota\",\"ThroughputMibps\":$thr,\"ProtocolTypes\":\"NFS4.1\",\"NFSAddressDNS\":\"$dns:/$acc/$name\",\"NFSAddress\":\"$dns:/$acc/$name\",\"QoSType\":\"Manual\",\"IOPS\":$iops,\"Id\":\"$sid\"}" |
225 | 234 | done |
226 | 235 | done |
227 | 236 |
|
228 | 237 | - name: Debug AFS storage data collected |
229 | 238 | when: afs_storage_metadata_results is defined |
230 | 239 | ansible.builtin.debug: |
231 | | - verbosity: 1 |
232 | 240 | var: afs_storage_metadata_results |
0 commit comments