| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: azure_rm_storageaccount_info |
| 15 |
|
| 16 |
version_added: "0.1.2" |
| 17 |
|
| 18 |
short_description: Get storage account facts |
| 19 |
|
| 20 |
description: |
| 21 |
- Get facts for one storage account or all storage accounts within a resource group. |
| 22 |
|
| 23 |
options: |
| 24 |
auth_mode: |
| 25 |
description: |
| 26 |
- The mode in which to run the command. C(login) mode will directly use your login credentials for the authentication. |
| 27 |
- The legacy C(key) mode will attempt to query for an account key if no authentication parameters for the account are provided. |
| 28 |
- Can also be set via the environment variable C(AZURE_STORAGE_AUTH_MODE). |
| 29 |
default: key |
| 30 |
type: str |
| 31 |
choices: |
| 32 |
- key |
| 33 |
- login |
| 34 |
version_added: "3.10.0" |
| 35 |
name: |
| 36 |
description: |
| 37 |
- Only show results for a specific account. |
| 38 |
type: str |
| 39 |
resource_group: |
| 40 |
description: |
| 41 |
- Limit results to a resource group. Required when filtering by name. |
| 42 |
type: str |
| 43 |
aliases: |
| 44 |
- resource_group_name |
| 45 |
tags: |
| 46 |
description: |
| 47 |
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. |
| 48 |
type: list |
| 49 |
elements: str |
| 50 |
show_connection_string: |
| 51 |
description: |
| 52 |
- Show the connection string for each of the storageaccount's endpoints. |
| 53 |
- For convenient usage, I(show_connection_string) will also show the access keys for each of the storageaccount's endpoints. |
| 54 |
- Note that it will cost a lot of time when list all storageaccount rather than query a single one. |
| 55 |
type: bool |
| 56 |
show_blob_cors: |
| 57 |
description: |
| 58 |
- Show the blob CORS settings for each blob related to the storage account. |
| 59 |
- Querying all storage accounts will take a long time. |
| 60 |
type: bool |
| 61 |
show_georeplication_stats: |
| 62 |
description: |
| 63 |
- Show the Geo Replication Stats for each storage account. |
| 64 |
- Using this option on an account that does not support georeplication will cause a delay in getting results. |
| 65 |
type: bool |
| 66 |
|
| 67 |
extends_documentation_fragment: |
| 68 |
- azure.azcollection.azure |
| 69 |
|
| 70 |
author: |
| 71 |
- Chris Houseknecht (@chouseknecht) |
| 72 |
- Matt Davis (@nitzmahone) |
| 73 |
|
| 74 |
''' |
| 75 |
|
| 76 |
EXAMPLES = ''' |
| 77 |
- name: Get facts for one account |
| 78 |
azure_rm_storageaccount_info: |
| 79 |
resource_group: myResourceGroup |
| 80 |
name: clh0002 |
| 81 |
|
| 82 |
- name: Get facts for all accounts in a resource group |
| 83 |
azure_rm_storageaccount_info: |
| 84 |
resource_group: myResourceGroup |
| 85 |
|
| 86 |
- name: Get facts for all accounts by tags |
| 87 |
azure_rm_storageaccount_info: |
| 88 |
tags: |
| 89 |
- testing |
| 90 |
- foo:bar |
| 91 |
''' |
| 92 |
|
| 93 |
RETURN = ''' |
| 94 |
azure_storageaccounts: |
| 95 |
description: |
| 96 |
- List of storage account dicts. |
| 97 |
returned: always |
| 98 |
type: list |
| 99 |
example: [{ |
| 100 |
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/myResourceGroups/testing/providers/Microsoft.Storage/storageAccounts/testaccount001", |
| 101 |
"location": "eastus2", |
| 102 |
"name": "testaccount001", |
| 103 |
"properties": { |
| 104 |
"accountType": "Standard_LRS", |
| 105 |
"creationTime": "2016-03-28T02:46:58.290113Z", |
| 106 |
"primaryEndpoints": { |
| 107 |
"blob": "https://testaccount001.blob.core.windows.net/", |
| 108 |
"file": "https://testaccount001.file.core.windows.net/", |
| 109 |
"queue": "https://testaccount001.queue.core.windows.net/", |
| 110 |
"table": "https://testaccount001.table.core.windows.net/" |
| 111 |
}, |
| 112 |
"primaryLocation": "eastus2", |
| 113 |
"provisioningState": "Succeeded", |
| 114 |
"statusOfPrimary": "Available" |
| 115 |
}, |
| 116 |
"tags": {}, |
| 117 |
"type": "Microsoft.Storage/storageAccounts" |
| 118 |
}] |
| 119 |
storageaccounts: |
| 120 |
description: |
| 121 |
- List of storage account dicts in resource module's parameter format. |
| 122 |
returned: always |
| 123 |
type: complex |
| 124 |
contains: |
| 125 |
id: |
| 126 |
description: |
| 127 |
- Resource ID. |
| 128 |
returned: always |
| 129 |
type: str |
| 130 |
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/t |
| 131 |
estaccount001" |
| 132 |
name: |
| 133 |
description: |
| 134 |
- Name of the storage account to update or create. |
| 135 |
returned: always |
| 136 |
type: str |
| 137 |
sample: testaccount001 |
| 138 |
location: |
| 139 |
description: |
| 140 |
- Valid Azure location. Defaults to location of the resource group. |
| 141 |
returned: always |
| 142 |
type: str |
| 143 |
sample: eastus |
| 144 |
account_type: |
| 145 |
description: |
| 146 |
- Type of storage account. |
| 147 |
- C(Standard_ZRS) and C(Premium_LRS) accounts cannot be changed to other account types. |
| 148 |
- Other account types cannot be changed to C(Standard_ZRS) or C(Premium_LRS). |
| 149 |
returned: always |
| 150 |
type: str |
| 151 |
sample: Standard_ZRS |
| 152 |
allow_cross_tenant_replication: |
| 153 |
description: |
| 154 |
- Allow or disallow cross AAD tenant object replication. |
| 155 |
type: bool |
| 156 |
returned: always |
| 157 |
sample: true |
| 158 |
allow_shared_key_access: |
| 159 |
description: |
| 160 |
- Indicates whether the storage account permits requests to be authorized with the account access key via Shared Key. |
| 161 |
type: bool |
| 162 |
returned: always |
| 163 |
sample: true |
| 164 |
default_to_o_auth_authentication: |
| 165 |
description: |
| 166 |
- A boolean flag which indicates whether the default authentication is OAuth or not. |
| 167 |
- The default interpretation is false for this property. |
| 168 |
type: bool |
| 169 |
returned: always |
| 170 |
sample: true |
| 171 |
custom_domain: |
| 172 |
description: |
| 173 |
- User domain assigned to the storage account. |
| 174 |
- Must be a dictionary with I(name) and I(use_sub_domain) keys where I(name) is the CNAME source. |
| 175 |
returned: always |
| 176 |
type: complex |
| 177 |
contains: |
| 178 |
name: |
| 179 |
description: |
| 180 |
- CNAME source. |
| 181 |
returned: always |
| 182 |
type: str |
| 183 |
sample: testaccount |
| 184 |
use_sub_domain: |
| 185 |
description: |
| 186 |
- Whether to use sub domain. |
| 187 |
returned: always |
| 188 |
type: bool |
| 189 |
sample: true |
| 190 |
encryption: |
| 191 |
description: |
| 192 |
- The encryption settings on the storage account. |
| 193 |
type: complex |
| 194 |
returned: always |
| 195 |
contains: |
| 196 |
key_source: |
| 197 |
description: |
| 198 |
- The encryption keySource (provider). |
| 199 |
type: str |
| 200 |
returned: always |
| 201 |
sample: Microsoft.Storage |
| 202 |
require_infrastructure_encryption: |
| 203 |
description: |
| 204 |
- A boolean indicating whether or not the service applies a secondary layer of encryption with platform managed keys for data at rest. |
| 205 |
type: bool |
| 206 |
returned: always |
| 207 |
sample: false |
| 208 |
services: |
| 209 |
description: |
| 210 |
- List of services which support encryption. |
| 211 |
type: dict |
| 212 |
returned: always |
| 213 |
contains: |
| 214 |
file: |
| 215 |
description: |
| 216 |
- The encryption function of the file storage service. |
| 217 |
type: dict |
| 218 |
returned: always |
| 219 |
sample: {'enabled': true} |
| 220 |
table: |
| 221 |
description: |
| 222 |
- The encryption function of the table storage service. |
| 223 |
type: dict |
| 224 |
returned: always |
| 225 |
sample: {'enabled': true} |
| 226 |
queue: |
| 227 |
description: |
| 228 |
- The encryption function of the queue storage service. |
| 229 |
type: dict |
| 230 |
returned: always |
| 231 |
sample: {'enabled': true} |
| 232 |
blob: |
| 233 |
description: |
| 234 |
- The encryption function of the blob storage service. |
| 235 |
type: dict |
| 236 |
returned: always |
| 237 |
sample: {'enabled': true} |
| 238 |
encryption_identity: |
| 239 |
description: |
| 240 |
- The identity to be used with service-side encryption at rest. |
| 241 |
type: dict |
| 242 |
returned: always |
| 243 |
sample: {"encryption_user_assigned_identity": \ |
| 244 |
"/subscriptions/xxxx/resourcegroups/testRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity-11"} |
| 245 |
key_vault_properties: |
| 246 |
description: |
| 247 |
- Dict of Microsoft Keyvault properties. |
| 248 |
- Create the Storage account with encryption enabled with Microsoft KeyVault for CMK. |
| 249 |
type: dict |
| 250 |
returned: always |
| 251 |
sample: {"key_name": "testkey", |
| 252 |
"key_vault_uri": "https://vxxxxxxx01.vault.azure.net/", |
| 253 |
"key_version": "0bd2556671c64fc998xxxxeb12"} |
| 254 |
is_hns_enabled: |
| 255 |
description: |
| 256 |
- Account HierarchicalNamespace enabled if sets to true. |
| 257 |
type: bool |
| 258 |
returned: always |
| 259 |
sample: true |
| 260 |
immutable_storage_with_versioning: |
| 261 |
description: |
| 262 |
- The property is immutable and can only be set to true at the account creation time. |
| 263 |
- When set to true, it enables object level immutability for all the containers in the account by default. |
| 264 |
type: complex |
| 265 |
returned: when-used |
| 266 |
contains: |
| 267 |
enabled: |
| 268 |
description: |
| 269 |
- A boolean flag which enables account-level immutability. |
| 270 |
- All the containers under such an account have object-level immutability enabled by default. |
| 271 |
type: bool |
| 272 |
returned: when-used |
| 273 |
sample: true |
| 274 |
immutability_policy: |
| 275 |
description: |
| 276 |
- Specifies the default account-level immutability policy which is inherited and |
| 277 |
applied to objects that do not possess an explicit immutability policy at the object level. |
| 278 |
- The object-level immutability policy has higher precedence than the container-level immutability policy, |
| 279 |
which has a higher precedence than the account-level immutability policy. |
| 280 |
type: dict |
| 281 |
returned: when-used |
| 282 |
contains: |
| 283 |
allow_protected_append_writes: |
| 284 |
description: |
| 285 |
- This property can only be changed for disabled and unlocked time-based retention policies. |
| 286 |
- When enabled, new blocks can be written to an append blob while maintaining immutability protection and compliance. |
| 287 |
- Only new blocks can be added and any existing blocks cannot be modified or deleted. |
| 288 |
type: bool |
| 289 |
returned: when-used |
| 290 |
sample: true |
| 291 |
state: |
| 292 |
description: |
| 293 |
- The ImmutabilityPolicy state defines the mode of the policy. |
| 294 |
type: str |
| 295 |
returned: when-used |
| 296 |
sample: Unlocked |
| 297 |
immutability_period_since_creation_in_days: |
| 298 |
description: |
| 299 |
- The immutability period for the blobs in the container since the policy creation, in days. |
| 300 |
type: int |
| 301 |
returned: when-used |
| 302 |
sample: true |
| 303 |
enable_nfs_v3: |
| 304 |
description: |
| 305 |
- NFS 3.0 protocol. |
| 306 |
type: bool |
| 307 |
returned: always |
| 308 |
sample: false |
| 309 |
kind: |
| 310 |
description: |
| 311 |
- The kind of storage. |
| 312 |
returned: always |
| 313 |
type: str |
| 314 |
sample: Storage |
| 315 |
access_tier: |
| 316 |
description: |
| 317 |
- The access tier for this storage account. |
| 318 |
returned: always |
| 319 |
type: str |
| 320 |
sample: Hot |
| 321 |
https_only: |
| 322 |
description: |
| 323 |
- Allows https traffic only to storage service when set to C(true). |
| 324 |
returned: always |
| 325 |
type: bool |
| 326 |
sample: false |
| 327 |
minimum_tls_version: |
| 328 |
description: |
| 329 |
- The minimum TLS version permitted on requests to storage. |
| 330 |
returned: always |
| 331 |
type: str |
| 332 |
sample: TLS1_2 |
| 333 |
public_network_access: |
| 334 |
description: |
| 335 |
- Public network access to Storage Account allowed or disallowed. |
| 336 |
returned: always |
| 337 |
type: str |
| 338 |
sample: Enabled |
| 339 |
allow_blob_public_access: |
| 340 |
description: |
| 341 |
- Public access to all blobs or containers in the storage account allowed or disallowed. |
| 342 |
returned: always |
| 343 |
type: bool |
| 344 |
sample: true |
| 345 |
network_acls: |
| 346 |
description: |
| 347 |
- A set of firewall, virtual network and resource instance rules. |
| 348 |
returned: always |
| 349 |
type: dict |
| 350 |
sample: { |
| 351 |
"bypass": "AzureServices", |
| 352 |
"default_action": "Deny", |
| 353 |
"virtual_network_rules": [ |
| 354 |
{ |
| 355 |
"action": "Allow", |
| 356 |
"id": "/subscriptions/mySubscriptionId/resourceGroups/myResourceGroup/ \ |
| 357 |
providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet" |
| 358 |
} |
| 359 |
], |
| 360 |
"ip_rules": [ |
| 361 |
{ |
| 362 |
"action": "Allow", |
| 363 |
"value": "1.2.3.4" |
| 364 |
}, |
| 365 |
{ |
| 366 |
"action": "Allow", |
| 367 |
"value": "123.234.123.0/24" |
| 368 |
} |
| 369 |
], |
| 370 |
"resource_access_rules": [ |
| 371 |
{ |
| 372 |
"resource_id": "/subscriptions/.../BackupVaults/myBackupVault", |
| 373 |
"tenant_id": "myTenantId" |
| 374 |
} |
| 375 |
] |
| 376 |
} |
| 377 |
provisioning_state: |
| 378 |
description: |
| 379 |
- The status of the storage account at the time the operation was called. |
| 380 |
- Possible values include C(Creating), C(ResolvingDNS), C(Succeeded). |
| 381 |
returned: always |
| 382 |
type: str |
| 383 |
sample: Succeeded |
| 384 |
failover_in_progress: |
| 385 |
description: |
| 386 |
- Status indicating the storage account is currently failing over to its secondary location. |
| 387 |
returned: always |
| 388 |
type: bool |
| 389 |
sample: False |
| 390 |
secondary_location: |
| 391 |
description: |
| 392 |
- The location of the geo-replicated secondary for the storage account. |
| 393 |
- Only available if the I(account_type=Standard_GRS) or I(account_type=Standard_RAGRS). |
| 394 |
returned: always |
| 395 |
type: str |
| 396 |
sample: westus |
| 397 |
status_of_primary: |
| 398 |
description: |
| 399 |
- Status of the primary location of the storage account; either C(available) or C(unavailable). |
| 400 |
returned: always |
| 401 |
type: str |
| 402 |
sample: available |
| 403 |
status_of_secondary: |
| 404 |
description: |
| 405 |
- Status of the secondary location of the storage account; either C(available) or C(unavailable). |
| 406 |
returned: always |
| 407 |
type: str |
| 408 |
sample: available |
| 409 |
primary_location: |
| 410 |
description: |
| 411 |
- The location of the primary data center for the storage account. |
| 412 |
returned: always |
| 413 |
type: str |
| 414 |
sample: eastus |
| 415 |
primary_endpoints: |
| 416 |
description: |
| 417 |
- URLs to retrieve a public I(blob), I(file), I(queue), or I(table) object. |
| 418 |
- Note that C(Standard_ZRS) and C(Premium_LRS) accounts only return the blob endpoint. |
| 419 |
returned: always |
| 420 |
type: complex |
| 421 |
contains: |
| 422 |
blob: |
| 423 |
description: |
| 424 |
- The primary blob endpoint and connection string. |
| 425 |
returned: always |
| 426 |
type: complex |
| 427 |
contains: |
| 428 |
endpoint: |
| 429 |
description: |
| 430 |
- The primary blob endpoint. |
| 431 |
returned: always |
| 432 |
type: str |
| 433 |
sample: "https://testaccount001.blob.core.windows.net/" |
| 434 |
connectionstring: |
| 435 |
description: |
| 436 |
- Connectionstring of the blob endpoint. |
| 437 |
returned: always |
| 438 |
type: str |
| 439 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;BlobEndpoint=X" |
| 440 |
file: |
| 441 |
description: |
| 442 |
- The primary file endpoint and connection string. |
| 443 |
returned: always |
| 444 |
type: complex |
| 445 |
contains: |
| 446 |
endpoint: |
| 447 |
description: |
| 448 |
- The primary file endpoint. |
| 449 |
returned: always |
| 450 |
type: str |
| 451 |
sample: "https://testaccount001.file.core.windows.net/" |
| 452 |
connectionstring: |
| 453 |
description: |
| 454 |
- Connectionstring of the file endpoint. |
| 455 |
returned: always |
| 456 |
type: str |
| 457 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;FileEndpoint=X" |
| 458 |
queue: |
| 459 |
description: |
| 460 |
- The primary queue endpoint and connection string. |
| 461 |
returned: always |
| 462 |
type: complex |
| 463 |
contains: |
| 464 |
endpoint: |
| 465 |
description: |
| 466 |
- The primary queue endpoint. |
| 467 |
returned: always |
| 468 |
type: str |
| 469 |
sample: "https://testaccount001.queue.core.windows.net/" |
| 470 |
connectionstring: |
| 471 |
description: |
| 472 |
- Connectionstring of the queue endpoint. |
| 473 |
returned: always |
| 474 |
type: str |
| 475 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;QueueEndpoint=X" |
| 476 |
table: |
| 477 |
description: |
| 478 |
- The primary table endpoint and connection string. |
| 479 |
returned: always |
| 480 |
type: complex |
| 481 |
contains: |
| 482 |
endpoint: |
| 483 |
description: |
| 484 |
- The primary table endpoint. |
| 485 |
returned: always |
| 486 |
type: str |
| 487 |
sample: "https://testaccount001.table.core.windows.net/" |
| 488 |
connectionstring: |
| 489 |
description: |
| 490 |
- Connectionstring of the table endpoint. |
| 491 |
returned: always |
| 492 |
type: str |
| 493 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;TableEndpoint=X" |
| 494 |
key: |
| 495 |
description: |
| 496 |
- The account key for the primary_endpoints |
| 497 |
returned: always |
| 498 |
type: str |
| 499 |
sample: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 500 |
secondary_endpoints: |
| 501 |
description: |
| 502 |
- The URLs to retrieve a public I(blob), I(file), I(queue), or I(table) object from the secondary location. |
| 503 |
- Only available if the SKU I(name=Standard_RAGRS). |
| 504 |
returned: always |
| 505 |
type: complex |
| 506 |
contains: |
| 507 |
blob: |
| 508 |
description: |
| 509 |
- The secondary blob endpoint and connection string. |
| 510 |
returned: always |
| 511 |
type: complex |
| 512 |
contains: |
| 513 |
endpoint: |
| 514 |
description: |
| 515 |
- The secondary blob endpoint. |
| 516 |
returned: always |
| 517 |
type: str |
| 518 |
sample: "https://testaccount001.blob.core.windows.net/" |
| 519 |
connectionstring: |
| 520 |
description: |
| 521 |
- Connectionstring of the blob endpoint. |
| 522 |
returned: always |
| 523 |
type: str |
| 524 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;BlobEndpoint=X" |
| 525 |
file: |
| 526 |
description: |
| 527 |
- The secondary file endpoint and connection string. |
| 528 |
returned: always |
| 529 |
type: complex |
| 530 |
contains: |
| 531 |
endpoint: |
| 532 |
description: |
| 533 |
- The secondary file endpoint. |
| 534 |
returned: always |
| 535 |
type: str |
| 536 |
sample: "https://testaccount001.file.core.windows.net/" |
| 537 |
connectionstring: |
| 538 |
description: |
| 539 |
- Connectionstring of the file endpoint. |
| 540 |
returned: always |
| 541 |
type: str |
| 542 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;FileEndpoint=X" |
| 543 |
queue: |
| 544 |
description: |
| 545 |
- The secondary queue endpoint and connection string. |
| 546 |
returned: always |
| 547 |
type: complex |
| 548 |
contains: |
| 549 |
endpoint: |
| 550 |
description: |
| 551 |
- The secondary queue endpoint. |
| 552 |
returned: always |
| 553 |
type: str |
| 554 |
sample: "https://testaccount001.queue.core.windows.net/" |
| 555 |
connectionstring: |
| 556 |
description: |
| 557 |
- Connectionstring of the queue endpoint. |
| 558 |
returned: always |
| 559 |
type: str |
| 560 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;QueueEndpoint=X" |
| 561 |
table: |
| 562 |
description: |
| 563 |
- The secondary table endpoint and connection string. |
| 564 |
returned: always |
| 565 |
type: complex |
| 566 |
contains: |
| 567 |
endpoint: |
| 568 |
description: |
| 569 |
- The secondary table endpoint. |
| 570 |
returned: always |
| 571 |
type: str |
| 572 |
sample: "https://testaccount001.table.core.windows.net/" |
| 573 |
connectionstring: |
| 574 |
description: |
| 575 |
- Connectionstring of the table endpoint. |
| 576 |
returned: always |
| 577 |
type: str |
| 578 |
sample: "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=X;AccountKey=X;TableEndpoint=X" |
| 579 |
key: |
| 580 |
description: |
| 581 |
- The account key for the secondary_endpoints |
| 582 |
sample: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 583 |
type: str |
| 584 |
georeplication_stats: |
| 585 |
description: |
| 586 |
- Parameters related to the status of geo-replication. |
| 587 |
- This will be null on accounts that don't support geo-replication. |
| 588 |
returned: always |
| 589 |
type: complex |
| 590 |
contains: |
| 591 |
can_failover: |
| 592 |
description: |
| 593 |
- Property indicating if fail over is supported by the account. |
| 594 |
type: bool |
| 595 |
sample: true |
| 596 |
last_sync_time: |
| 597 |
description: |
| 598 |
- Writes to the primary before this time are guaranteed to be replicated to the secondary. |
| 599 |
type: str |
| 600 |
sample: "2023-04-10T21:22:15+00:00" |
| 601 |
sync_status: |
| 602 |
description: |
| 603 |
- Property showing status of the secondary region. |
| 604 |
- Known values are "Live", "Bootstrap", and "Unavailable". |
| 605 |
type: str |
| 606 |
sample: Live |
| 607 |
tags: |
| 608 |
description: |
| 609 |
- Resource tags. |
| 610 |
returned: always |
| 611 |
type: dict |
| 612 |
sample: { "tag1": "abc" } |
| 613 |
large_file_shares_state: |
| 614 |
description: |
| 615 |
- Allow large file shares if sets to Enabled. |
| 616 |
type: str |
| 617 |
returned: always |
| 618 |
sample: Enabled |
| 619 |
static_website: |
| 620 |
description: |
| 621 |
- Static website configuration for the storage account. |
| 622 |
returned: always |
| 623 |
version_added: "1.13.0" |
| 624 |
type: complex |
| 625 |
contains: |
| 626 |
enabled: |
| 627 |
description: |
| 628 |
- Whether this account is hosting a static website. |
| 629 |
returned: always |
| 630 |
type: bool |
| 631 |
sample: true |
| 632 |
index_document: |
| 633 |
description: |
| 634 |
- The default name of the index page under each directory. |
| 635 |
returned: always |
| 636 |
type: str |
| 637 |
sample: index.html |
| 638 |
error_document404_path: |
| 639 |
description: |
| 640 |
- The absolute path of the custom 404 page. |
| 641 |
returned: always |
| 642 |
type: str |
| 643 |
sample: error.html |
| 644 |
''' |
| 645 |
|
| 646 |
|
| 647 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 648 |
from ansible.module_utils._text import to_native |
| 649 |
from ansible.module_utils.basic import env_fallback |
| 650 |
|
| 651 |
|
| 652 |
AZURE_OBJECT_CLASS = 'StorageAccount' |
| 653 |
|
| 654 |
|
| 655 |
class AzureRMStorageAccountInfo(AzureRMModuleBase): |
| 656 |
def __init__(self): |
| 657 |
|
| 658 |
self.module_arg_spec = dict( |
| 659 |
auth_mode=dict( |
| 660 |
type='str', |
| 661 |
choices=['key', 'login'], |
| 662 |
fallback=(env_fallback, ['AZURE_STORAGE_AUTH_MODE']), |
| 663 |
default="key" |
| 664 |
), |
| 665 |
name=dict(type='str'), |
| 666 |
resource_group=dict(type='str', aliases=['resource_group_name']), |
| 667 |
tags=dict(type='list', elements='str'), |
| 668 |
show_connection_string=dict(type='bool'), |
| 669 |
show_blob_cors=dict(type='bool'), |
| 670 |
show_georeplication_stats=dict(type='bool') |
| 671 |
) |
| 672 |
|
| 673 |
self.results = dict( |
| 674 |
changed=False, |
| 675 |
storageaccounts=[] |
| 676 |
) |
| 677 |
|
| 678 |
self.name = None |
| 679 |
self.resource_group = None |
| 680 |
self.tags = None |
| 681 |
self.show_connection_string = None |
| 682 |
self.show_blob_cors = None |
| 683 |
self.show_georeplication_stats = None |
| 684 |
|
| 685 |
super(AzureRMStorageAccountInfo, self).__init__(self.module_arg_spec, |
| 686 |
supports_check_mode=True, |
| 687 |
supports_tags=False, |
| 688 |
facts_module=True) |
| 689 |
|
| 690 |
def exec_module(self, **kwargs): |
| 691 |
|
| 692 |
for key in self.module_arg_spec: |
| 693 |
setattr(self, key, kwargs[key]) |
| 694 |
|
| 695 |
if self.name and not self.resource_group: |
| 696 |
self.fail("Parameter error: resource group required when filtering by name.") |
| 697 |
|
| 698 |
results = [] |
| 699 |
if self.name: |
| 700 |
results = self.get_account() |
| 701 |
elif self.resource_group: |
| 702 |
results = self.list_resource_group() |
| 703 |
else: |
| 704 |
results = self.list_all() |
| 705 |
|
| 706 |
filtered = self.filter_tag(results) |
| 707 |
|
| 708 |
self.results['storageaccounts'] = self.format_to_dict(filtered) |
| 709 |
return self.results |
| 710 |
|
| 711 |
def get_account(self): |
| 712 |
self.log('Get properties for account {0}'.format(self.name)) |
| 713 |
account = None |
| 714 |
try: |
| 715 |
expand = None |
| 716 |
if (self.show_georeplication_stats): |
| 717 |
expand = 'georeplicationstats' |
| 718 |
account = self.storage_client.storage_accounts.get_properties(self.resource_group, self.name, expand=expand) |
| 719 |
return [account] |
| 720 |
except Exception as exc: |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
if "InvalidAccountType" in str(exc) or "LastSyncTimeUnavailable" in str(exc): |
| 725 |
account = self.storage_client.storage_accounts.get_properties(self.resource_group, self.name) |
| 726 |
return [account] |
| 727 |
|
| 728 |
if "AuthorizationFailed" in str(exc): |
| 729 |
self.fail("Error authenticating with the Azure storage API. {0}".format(str(exc))) |
| 730 |
|
| 731 |
return [] |
| 732 |
|
| 733 |
def list_resource_group(self): |
| 734 |
self.log('List items') |
| 735 |
try: |
| 736 |
response = self.storage_client.storage_accounts.list_by_resource_group(self.resource_group) |
| 737 |
except Exception as exc: |
| 738 |
self.fail("Error listing for resource group {0} - {1}".format(self.resource_group, str(exc))) |
| 739 |
|
| 740 |
return response |
| 741 |
|
| 742 |
def list_all(self): |
| 743 |
self.log('List all items') |
| 744 |
try: |
| 745 |
response = self.storage_client.storage_accounts.list() |
| 746 |
except Exception as exc: |
| 747 |
self.fail("Error listing all items - {0}".format(str(exc))) |
| 748 |
|
| 749 |
return response |
| 750 |
|
| 751 |
def filter_tag(self, raw): |
| 752 |
return [item for item in raw if self.has_tags(item.tags, self.tags)] |
| 753 |
|
| 754 |
def serialize(self, raw): |
| 755 |
return [self.serialize_obj(item, AZURE_OBJECT_CLASS) for item in raw] |
| 756 |
|
| 757 |
def format_to_dict(self, raw): |
| 758 |
return [self.account_obj_to_dict(item) for item in raw] |
| 759 |
|
| 760 |
def account_obj_to_dict(self, account_obj): |
| 761 |
account_dict = dict( |
| 762 |
id=account_obj.id, |
| 763 |
name=account_obj.name, |
| 764 |
location=account_obj.location, |
| 765 |
failover_in_progress=(account_obj.failover_in_progress |
| 766 |
if account_obj.failover_in_progress is not None else False), |
| 767 |
access_tier=(account_obj.access_tier |
| 768 |
if account_obj.access_tier is not None else None), |
| 769 |
account_type=account_obj.sku.name, |
| 770 |
kind=account_obj.kind if account_obj.kind else None, |
| 771 |
provisioning_state=account_obj.provisioning_state, |
| 772 |
secondary_location=account_obj.secondary_location, |
| 773 |
status_of_primary=(account_obj.status_of_primary |
| 774 |
if account_obj.status_of_primary is not None else None), |
| 775 |
status_of_secondary=(account_obj.status_of_secondary |
| 776 |
if account_obj.status_of_secondary is not None else None), |
| 777 |
primary_location=account_obj.primary_location, |
| 778 |
https_only=account_obj.enable_https_traffic_only, |
| 779 |
minimum_tls_version=account_obj.minimum_tls_version, |
| 780 |
public_network_access=account_obj.public_network_access, |
| 781 |
allow_blob_public_access=account_obj.allow_blob_public_access, |
| 782 |
is_hns_enabled=account_obj.is_hns_enabled if account_obj.is_hns_enabled else False, |
| 783 |
large_file_shares_state=account_obj.large_file_shares_state, |
| 784 |
enable_nfs_v3=account_obj.enable_nfs_v3 if hasattr(account_obj, 'enable_nfs_v3') else None, |
| 785 |
allow_cross_tenant_replication=account_obj.allow_cross_tenant_replication, |
| 786 |
allow_shared_key_access=account_obj.allow_shared_key_access, |
| 787 |
default_to_o_auth_authentication=account_obj.default_to_o_auth_authentication, |
| 788 |
static_website=dict( |
| 789 |
enabled=False, |
| 790 |
index_document=None, |
| 791 |
error_document404_path=None, |
| 792 |
), |
| 793 |
immutable_storage_with_versioning=account_obj.immutable_storage_with_versioning.as_dict() if account_obj.immutable_storage_with_versioning else None |
| 794 |
) |
| 795 |
|
| 796 |
account_dict['geo_replication_stats'] = None |
| 797 |
if account_obj.geo_replication_stats is not None: |
| 798 |
account_dict['geo_replication_stats'] = dict( |
| 799 |
status=account_obj.geo_replication_stats.status, |
| 800 |
can_failover=account_obj.geo_replication_stats.can_failover, |
| 801 |
last_sync_time=account_obj.geo_replication_stats.last_sync_time |
| 802 |
) |
| 803 |
|
| 804 |
id_dict = self.parse_resource_to_dict(account_obj.id) |
| 805 |
account_dict['resource_group'] = id_dict.get('resource_group') |
| 806 |
account_key = self.get_connectionstring(account_dict['resource_group'], account_dict['name']) |
| 807 |
account_dict['custom_domain'] = None |
| 808 |
if account_obj.custom_domain: |
| 809 |
account_dict['custom_domain'] = dict( |
| 810 |
name=account_obj.custom_domain.name, |
| 811 |
use_sub_domain=account_obj.custom_domain.use_sub_domain |
| 812 |
) |
| 813 |
|
| 814 |
account_dict['network_acls'] = None |
| 815 |
if account_obj.network_rule_set: |
| 816 |
account_dict['network_acls'] = dict( |
| 817 |
bypass=account_obj.network_rule_set.bypass, |
| 818 |
default_action=account_obj.network_rule_set.default_action, |
| 819 |
) |
| 820 |
|
| 821 |
account_dict['network_acls']['virtual_network_rules'] = [] |
| 822 |
if account_obj.network_rule_set.virtual_network_rules: |
| 823 |
for rule in account_obj.network_rule_set.virtual_network_rules: |
| 824 |
account_dict['network_acls']['virtual_network_rules'].append( |
| 825 |
dict(id=rule.virtual_network_resource_id, action=rule.action) |
| 826 |
) |
| 827 |
|
| 828 |
account_dict['network_acls']['ip_rules'] = [] |
| 829 |
if account_obj.network_rule_set.ip_rules: |
| 830 |
for rule in account_obj.network_rule_set.ip_rules: |
| 831 |
account_dict['network_acls']['ip_rules'].append( |
| 832 |
dict(value=rule.ip_address_or_range, action=rule.action) |
| 833 |
) |
| 834 |
|
| 835 |
account_dict['network_acls']['resource_access_rules'] = [] |
| 836 |
if getattr(account_obj.network_rule_set, 'resource_access_rules', None): |
| 837 |
for rule in account_obj.network_rule_set.resource_access_rules: |
| 838 |
account_dict['network_acls']['resource_access_rules'].append( |
| 839 |
dict(resource_id=rule.resource_id, tenant_id=rule.tenant_id) |
| 840 |
) |
| 841 |
|
| 842 |
account_dict['primary_endpoints'] = None |
| 843 |
if account_obj.primary_endpoints: |
| 844 |
account_dict['primary_endpoints'] = dict( |
| 845 |
blob=self.format_endpoint_dict(account_dict['name'], account_key[0], account_obj.primary_endpoints.blob, 'blob'), |
| 846 |
file=self.format_endpoint_dict(account_dict['name'], account_key[0], account_obj.primary_endpoints.file, 'file'), |
| 847 |
queue=self.format_endpoint_dict(account_dict['name'], account_key[0], account_obj.primary_endpoints.queue, 'queue'), |
| 848 |
table=self.format_endpoint_dict(account_dict['name'], account_key[0], account_obj.primary_endpoints.table, 'table') |
| 849 |
) |
| 850 |
if account_key[0]: |
| 851 |
account_dict['primary_endpoints']['key'] = '{0}'.format(account_key[0]) |
| 852 |
account_dict['secondary_endpoints'] = None |
| 853 |
if account_obj.secondary_endpoints: |
| 854 |
account_dict['secondary_endpoints'] = dict( |
| 855 |
blob=self.format_endpoint_dict(account_dict['name'], account_key[1], account_obj.secondary_endpoints.blob, 'blob'), |
| 856 |
file=self.format_endpoint_dict(account_dict['name'], account_key[1], account_obj.secondary_endpoints.file, 'file'), |
| 857 |
queue=self.format_endpoint_dict(account_dict['name'], account_key[1], account_obj.secondary_endpoints.queue, 'queue'), |
| 858 |
table=self.format_endpoint_dict(account_dict['name'], account_key[1], account_obj.secondary_endpoints.table, 'table'), |
| 859 |
) |
| 860 |
if account_key[1]: |
| 861 |
account_dict['secondary_endpoints']['key'] = '{0}'.format(account_key[1]) |
| 862 |
account_dict['tags'] = None |
| 863 |
if account_obj.tags: |
| 864 |
account_dict['tags'] = account_obj.tags |
| 865 |
blob_mgmt_props = self.get_blob_mgmt_props(account_dict['resource_group'], account_dict['name']) |
| 866 |
if blob_mgmt_props and blob_mgmt_props.cors and blob_mgmt_props.cors.cors_rules: |
| 867 |
account_dict['blob_cors'] = [dict( |
| 868 |
allowed_origins=[to_native(o) for o in x.allowed_origins], |
| 869 |
allowed_methods=[to_native(m) for m in x.allowed_methods], |
| 870 |
max_age_in_seconds=x.max_age_in_seconds, |
| 871 |
exposed_headers=[to_native(h) for h in x.exposed_headers], |
| 872 |
allowed_headers=[to_native(h) for h in x.allowed_headers], |
| 873 |
) for x in blob_mgmt_props.cors.cors_rules] |
| 874 |
blob_client_props = self.get_blob_client_props(account_dict['resource_group'], account_dict['name'], account_dict['kind']) |
| 875 |
if blob_client_props and blob_client_props['static_website']: |
| 876 |
static_website = blob_client_props['static_website'] |
| 877 |
account_dict['static_website'] = dict( |
| 878 |
enabled=static_website.enabled, |
| 879 |
index_document=static_website.index_document, |
| 880 |
error_document404_path=static_website.error_document404_path, |
| 881 |
) |
| 882 |
|
| 883 |
account_dict['encryption'] = dict() |
| 884 |
if account_obj.encryption: |
| 885 |
account_dict['encryption']['require_infrastructure_encryption'] = account_obj.encryption.require_infrastructure_encryption |
| 886 |
account_dict['encryption']['key_source'] = account_obj.encryption.key_source |
| 887 |
|
| 888 |
if account_obj.encryption.services: |
| 889 |
account_dict['encryption']['services'] = dict() |
| 890 |
|
| 891 |
if account_obj.encryption.services.file: |
| 892 |
account_dict['encryption']['services']['file'] = dict(enabled=True) |
| 893 |
if account_obj.encryption.services.table: |
| 894 |
account_dict['encryption']['services']['table'] = dict(enabled=True) |
| 895 |
if account_obj.encryption.services.queue: |
| 896 |
account_dict['encryption']['services']['queue'] = dict(enabled=True) |
| 897 |
if account_obj.encryption.services.blob: |
| 898 |
account_dict['encryption']['services']['blob'] = dict(enabled=True) |
| 899 |
if account_obj.encryption.encryption_identity: |
| 900 |
account_dict['encryption']['encryption_identity'] = dict( |
| 901 |
encryption_user_assigned_identity=account_obj.encryption.encryption_identity.encryption_user_assigned_identity) |
| 902 |
else: |
| 903 |
account_dict['encryption']['encryption_identity'] = None |
| 904 |
if account_obj.encryption.key_vault_properties: |
| 905 |
account_dict['encryption']['key_vault_properties'] = dict(key_vault_uri=account_obj.encryption.key_vault_properties.key_vault_uri, |
| 906 |
key_name=account_obj.encryption.key_vault_properties.key_name, |
| 907 |
key_version=account_obj.encryption.key_vault_properties.key_version) |
| 908 |
else: |
| 909 |
account_dict['encryption']['key_vault_properties'] = None |
| 910 |
|
| 911 |
account_dict['identity'] = dict() |
| 912 |
if account_obj.identity: |
| 913 |
account_dict['identity'] = account_obj.identity.as_dict() |
| 914 |
|
| 915 |
return account_dict |
| 916 |
|
| 917 |
def format_endpoint_dict(self, name, key, endpoint, storagetype, protocol='https'): |
| 918 |
result = dict(endpoint=endpoint) |
| 919 |
if key: |
| 920 |
result['connectionstring'] = 'DefaultEndpointsProtocol={0};EndpointSuffix={1};AccountName={2};AccountKey={3};{4}Endpoint={5}'.format( |
| 921 |
protocol, |
| 922 |
self._cloud_environment.suffixes.storage_endpoint, |
| 923 |
name, |
| 924 |
key, |
| 925 |
str.title(storagetype), |
| 926 |
endpoint) |
| 927 |
return result |
| 928 |
|
| 929 |
def get_blob_mgmt_props(self, resource_group, name): |
| 930 |
if not self.show_blob_cors: |
| 931 |
return None |
| 932 |
try: |
| 933 |
return self.storage_client.blob_services.get_service_properties(resource_group, name) |
| 934 |
except Exception: |
| 935 |
pass |
| 936 |
return None |
| 937 |
|
| 938 |
def get_blob_client_props(self, resource_group, name, kind): |
| 939 |
if kind == "FileStorage": |
| 940 |
return None |
| 941 |
try: |
| 942 |
return self.get_blob_service_client(resource_group, name, self.auth_mode).get_service_properties() |
| 943 |
except Exception: |
| 944 |
pass |
| 945 |
return None |
| 946 |
|
| 947 |
def get_connectionstring(self, resource_group, name): |
| 948 |
keys = ['', ''] |
| 949 |
if not self.show_connection_string: |
| 950 |
return keys |
| 951 |
try: |
| 952 |
cred = self.storage_client.storage_accounts.list_keys(resource_group, name) |
| 953 |
|
| 954 |
try: |
| 955 |
keys = [cred.keys[0].value, cred.keys[1].value] |
| 956 |
except AttributeError: |
| 957 |
keys = [cred.key1, cred.key2] |
| 958 |
except Exception: |
| 959 |
pass |
| 960 |
return keys |
| 961 |
|
| 962 |
|
| 963 |
def main(): |
| 964 |
AzureRMStorageAccountInfo() |
| 965 |
|
| 966 |
|
| 967 |
if __name__ == '__main__': |
| 968 |
main() |