| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_postgresqlflexibleserver_info |
| 14 |
version_added: "2.2.0" |
| 15 |
short_description: Get Azure PostgreSQL Flexible Server facts |
| 16 |
description: |
| 17 |
- Get facts of PostgreSQL Flexible Server. |
| 18 |
|
| 19 |
options: |
| 20 |
resource_group: |
| 21 |
description: |
| 22 |
- The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. |
| 23 |
type: str |
| 24 |
name: |
| 25 |
description: |
| 26 |
- The name of the server. |
| 27 |
type: str |
| 28 |
tags: |
| 29 |
description: |
| 30 |
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. |
| 31 |
type: list |
| 32 |
elements: str |
| 33 |
|
| 34 |
extends_documentation_fragment: |
| 35 |
- azure.azcollection.azure |
| 36 |
|
| 37 |
author: |
| 38 |
- xuzhang3 (@xuzhang3) |
| 39 |
- Fred-sun (@Fred-sun) |
| 40 |
|
| 41 |
''' |
| 42 |
|
| 43 |
EXAMPLES = ''' |
| 44 |
- name: Get instance of PostgreSQL Flexible Server |
| 45 |
azure_rm_postgresqlflexibleserver_info: |
| 46 |
resource_group: myResourceGroup |
| 47 |
name: server_name |
| 48 |
|
| 49 |
- name: List instances of PostgreSQL Flexible Server |
| 50 |
azure_rm_postgresqlflexibleserver_info: |
| 51 |
resource_group: myResourceGroup |
| 52 |
tags: |
| 53 |
- key |
| 54 |
''' |
| 55 |
|
| 56 |
RETURN = ''' |
| 57 |
servers: |
| 58 |
description: |
| 59 |
- A list of dictionaries containing facts for PostgreSQL Flexible servers. |
| 60 |
returned: always |
| 61 |
type: complex |
| 62 |
contains: |
| 63 |
id: |
| 64 |
description: |
| 65 |
- Resource ID of the postgresql flexible server. |
| 66 |
returned: always |
| 67 |
type: str |
| 68 |
sample: "/subscriptions/xxx/resourceGroups/myResourceGroup/providers/Microsoft.DBforPostgreSQL/flexibleservers/postgresql3" |
| 69 |
resource_group: |
| 70 |
description: |
| 71 |
- Resource group name. |
| 72 |
returned: always |
| 73 |
type: str |
| 74 |
sample: myResourceGroup |
| 75 |
name: |
| 76 |
description: |
| 77 |
- Resource name. |
| 78 |
returned: always |
| 79 |
type: str |
| 80 |
sample: postgreabdud1223 |
| 81 |
location: |
| 82 |
description: |
| 83 |
- The location the resource resides in. |
| 84 |
returned: always |
| 85 |
type: str |
| 86 |
sample: eastus |
| 87 |
sku: |
| 88 |
description: |
| 89 |
- The SKU of the server. |
| 90 |
returned: always |
| 91 |
type: complex |
| 92 |
contains: |
| 93 |
name: |
| 94 |
description: |
| 95 |
- The name of the SKU. |
| 96 |
returned: always |
| 97 |
type: str |
| 98 |
sample: Standard_B1ms |
| 99 |
tier: |
| 100 |
description: |
| 101 |
- The tier of the particular SKU. |
| 102 |
returned: always |
| 103 |
type: str |
| 104 |
sample: Burstable |
| 105 |
storage: |
| 106 |
description: |
| 107 |
- The maximum storage allowed for a server. |
| 108 |
returned: always |
| 109 |
type: complex |
| 110 |
contains: |
| 111 |
storage_size_gb: |
| 112 |
description: |
| 113 |
- Max storage allowed for a server. |
| 114 |
type: int |
| 115 |
returned: always |
| 116 |
sample: 128 |
| 117 |
administrator_login: |
| 118 |
description: |
| 119 |
- The administrator's login name of a server. |
| 120 |
returned: always |
| 121 |
type: str |
| 122 |
sample: azureuser |
| 123 |
version: |
| 124 |
description: |
| 125 |
- Flexible Server version. |
| 126 |
returned: always |
| 127 |
type: str |
| 128 |
sample: "12" |
| 129 |
fully_qualified_domain_name: |
| 130 |
description: |
| 131 |
- The fully qualified domain name of the flexible server. |
| 132 |
returned: always |
| 133 |
type: str |
| 134 |
sample: postflexiblefredpgsqlflexible.postgres.database.azure.com |
| 135 |
availability_zone: |
| 136 |
description: |
| 137 |
- availability zone information of the server. |
| 138 |
type: str |
| 139 |
returned: always |
| 140 |
sample: 1 |
| 141 |
backup: |
| 142 |
description: |
| 143 |
- Backup properties of a server. |
| 144 |
type: complex |
| 145 |
returned: always |
| 146 |
contains: |
| 147 |
backup_retention_days: |
| 148 |
description: |
| 149 |
- Backup retention days for the server. |
| 150 |
type: int |
| 151 |
returned: always |
| 152 |
sample: 7 |
| 153 |
geo_redundant_backup: |
| 154 |
description: |
| 155 |
- A value indicating whether Geo-Redundant backup is enabled on the server. |
| 156 |
type: str |
| 157 |
returned: always |
| 158 |
sample: Disabled |
| 159 |
high_availability: |
| 160 |
description: |
| 161 |
- High availability properties of a server. |
| 162 |
type: complex |
| 163 |
returned: always |
| 164 |
contains: |
| 165 |
mode: |
| 166 |
description: |
| 167 |
- The HA mode for the server. |
| 168 |
returned: always |
| 169 |
sample: Disabled |
| 170 |
type: str |
| 171 |
standby_availability_zone: |
| 172 |
description: |
| 173 |
- availability zone information of the standby. |
| 174 |
type: str |
| 175 |
returned: always |
| 176 |
sample: null |
| 177 |
maintenance_window: |
| 178 |
description: |
| 179 |
- Maintenance window properties of a server. |
| 180 |
type: complex |
| 181 |
returned: always |
| 182 |
contains: |
| 183 |
custom_window: |
| 184 |
description: |
| 185 |
- Indicates whether custom window is enabled or disabled. |
| 186 |
returned: always |
| 187 |
sample: Enabled |
| 188 |
type: str |
| 189 |
day_of_week: |
| 190 |
description: |
| 191 |
- Day of week for maintenance window. |
| 192 |
returned: always |
| 193 |
sample: 0 |
| 194 |
type: int |
| 195 |
start_hour: |
| 196 |
description: |
| 197 |
- Start hour for maintenance window. |
| 198 |
type: int |
| 199 |
returned: always |
| 200 |
sample: 8 |
| 201 |
start_minute: |
| 202 |
description: |
| 203 |
- Start minute for maintenance window. |
| 204 |
type: int |
| 205 |
returned: always |
| 206 |
sample: 0 |
| 207 |
network: |
| 208 |
description: |
| 209 |
- Network properties of a server. |
| 210 |
type: complex |
| 211 |
returned: always |
| 212 |
contains: |
| 213 |
delegated_subnet_resource_id: |
| 214 |
description: |
| 215 |
- Delegated subnet arm resource id. |
| 216 |
type: str |
| 217 |
returned: always |
| 218 |
sample: null |
| 219 |
private_dns_zone_arm_resource_id: |
| 220 |
description: |
| 221 |
- Private dns zone arm resource id. |
| 222 |
type: str |
| 223 |
returned: always |
| 224 |
sample: null |
| 225 |
public_network_access: |
| 226 |
description: |
| 227 |
- Public network access is enabled or not. |
| 228 |
type: str |
| 229 |
returned: always |
| 230 |
sample: Enabled |
| 231 |
point_in_time_utc: |
| 232 |
description: |
| 233 |
- Restore point creation time (ISO8601 format). |
| 234 |
type: str |
| 235 |
sample: null |
| 236 |
returned: always |
| 237 |
source_server_resource_id: |
| 238 |
description: |
| 239 |
- The source server resource ID to restore from. |
| 240 |
type: str |
| 241 |
returned: always |
| 242 |
sample: null |
| 243 |
system_data: |
| 244 |
description: |
| 245 |
- The system metadata relating to this resource. |
| 246 |
type: complex |
| 247 |
returned: always |
| 248 |
contains: |
| 249 |
created_by: |
| 250 |
description: |
| 251 |
- The identity that created the resource. |
| 252 |
type: str |
| 253 |
returned: always |
| 254 |
sample: null |
| 255 |
created_by_type: |
| 256 |
description: |
| 257 |
- The type of identity that created the resource. |
| 258 |
returned: always |
| 259 |
type: str |
| 260 |
sample: null |
| 261 |
created_at: |
| 262 |
description: |
| 263 |
- The timestamp of resource creation (UTC). |
| 264 |
returned: always |
| 265 |
sample: null |
| 266 |
type: str |
| 267 |
last_modified_by: |
| 268 |
description: |
| 269 |
- The identity that last modified the resource. |
| 270 |
type: str |
| 271 |
returned: always |
| 272 |
sample: null |
| 273 |
last_modified_by_type: |
| 274 |
description: |
| 275 |
- The type of identity that last modified the resource. |
| 276 |
returned: always |
| 277 |
sample: null |
| 278 |
type: str |
| 279 |
last_modified_at: |
| 280 |
description: |
| 281 |
- The timestamp of resource last modification (UTC). |
| 282 |
returned: always |
| 283 |
sample: null |
| 284 |
type: str |
| 285 |
identity: |
| 286 |
description: |
| 287 |
- Identity for the Server. |
| 288 |
type: complex |
| 289 |
returned: when available |
| 290 |
contains: |
| 291 |
type: |
| 292 |
description: |
| 293 |
- Type of the managed identity |
| 294 |
returned: always |
| 295 |
sample: UserAssigned |
| 296 |
type: str |
| 297 |
user_assigned_identities: |
| 298 |
description: |
| 299 |
- User Assigned Managed Identities and its options |
| 300 |
returned: always |
| 301 |
type: complex |
| 302 |
contains: |
| 303 |
id: |
| 304 |
description: |
| 305 |
- Dict of the user assigned identities IDs associated to the Resource |
| 306 |
returned: always |
| 307 |
type: dict |
| 308 |
elements: dict |
| 309 |
tags: |
| 310 |
description: |
| 311 |
- Tags assigned to the resource. Dictionary of string:string pairs. |
| 312 |
type: dict |
| 313 |
returned: always |
| 314 |
sample: { tag1: abc } |
| 315 |
auth_config: |
| 316 |
description: |
| 317 |
- AuthConfig properties of a server. |
| 318 |
type: dict |
| 319 |
returned: always |
| 320 |
sample: {"active_directory_auth": "Disabled", "password_auth": "Enabled", "tenant_id": null} |
| 321 |
''' |
| 322 |
|
| 323 |
|
| 324 |
try: |
| 325 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 326 |
import azure.mgmt.rdbms.postgresql_flexibleservers.models as PostgreSQLFlexibleModels |
| 327 |
from azure.core.exceptions import ResourceNotFoundError |
| 328 |
except ImportError: |
| 329 |
|
| 330 |
pass |
| 331 |
|
| 332 |
|
| 333 |
class AzureRMPostgreSqlFlexibleServersInfo(AzureRMModuleBase): |
| 334 |
def __init__(self): |
| 335 |
|
| 336 |
self.module_arg_spec = dict( |
| 337 |
resource_group=dict( |
| 338 |
type='str', |
| 339 |
), |
| 340 |
name=dict( |
| 341 |
type='str' |
| 342 |
), |
| 343 |
tags=dict( |
| 344 |
type='list', |
| 345 |
elements='str' |
| 346 |
) |
| 347 |
) |
| 348 |
|
| 349 |
self.results = dict( |
| 350 |
changed=False |
| 351 |
) |
| 352 |
self.resource_group = None |
| 353 |
self.name = None |
| 354 |
self.tags = None |
| 355 |
super(AzureRMPostgreSqlFlexibleServersInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True) |
| 356 |
|
| 357 |
def exec_module(self, **kwargs): |
| 358 |
for key in self.module_arg_spec: |
| 359 |
setattr(self, key, kwargs[key]) |
| 360 |
|
| 361 |
if self.resource_group is not None and self.name is not None: |
| 362 |
self.results['servers'] = self.get() |
| 363 |
elif self.resource_group is not None: |
| 364 |
self.results['servers'] = self.list_by_resource_group() |
| 365 |
else: |
| 366 |
self.results['servers'] = self.list_all() |
| 367 |
return self.results |
| 368 |
|
| 369 |
def get(self): |
| 370 |
response = None |
| 371 |
results = [] |
| 372 |
try: |
| 373 |
response = self.postgresql_flexible_client.servers.get(resource_group_name=self.resource_group, |
| 374 |
server_name=self.name) |
| 375 |
self.log("Response : {0}".format(response)) |
| 376 |
except ResourceNotFoundError: |
| 377 |
self.log('Could not get facts for PostgreSQL Flexible Server.') |
| 378 |
|
| 379 |
if response and self.has_tags(response.tags, self.tags): |
| 380 |
results.append(self.format_item(response)) |
| 381 |
|
| 382 |
return results |
| 383 |
|
| 384 |
def list_by_resource_group(self): |
| 385 |
response = None |
| 386 |
results = [] |
| 387 |
try: |
| 388 |
response = self.postgresql_flexible_client.servers.list_by_resource_group(resource_group_name=self.resource_group) |
| 389 |
self.log("Response : {0}".format(response)) |
| 390 |
except Exception: |
| 391 |
self.log('Could not get facts for PostgreSQL Flexible Servers.') |
| 392 |
|
| 393 |
if response is not None: |
| 394 |
for item in response: |
| 395 |
if self.has_tags(item.tags, self.tags): |
| 396 |
results.append(self.format_item(item)) |
| 397 |
|
| 398 |
return results |
| 399 |
|
| 400 |
def list_all(self): |
| 401 |
response = None |
| 402 |
results = [] |
| 403 |
try: |
| 404 |
response = self.postgresql_flexible_client.servers.list() |
| 405 |
self.log("Response : {0}".format(response)) |
| 406 |
except Exception: |
| 407 |
self.log('Could not get facts for PostgreSQL Flexible Servers.') |
| 408 |
|
| 409 |
if response is not None: |
| 410 |
for item in response: |
| 411 |
if self.has_tags(item.tags, self.tags): |
| 412 |
results.append(self.format_item(item)) |
| 413 |
|
| 414 |
return results |
| 415 |
|
| 416 |
def format_item(self, item): |
| 417 |
result = dict( |
| 418 |
id=item.id, |
| 419 |
resource_group=self.resource_group, |
| 420 |
name=item.name, |
| 421 |
sku=dict(), |
| 422 |
location=item.location, |
| 423 |
tags=item.tags, |
| 424 |
system_data=dict(), |
| 425 |
administrator_login=item.administrator_login, |
| 426 |
version=item.version, |
| 427 |
minor_version=item.minor_version, |
| 428 |
fully_qualified_domain_name=item.fully_qualified_domain_name, |
| 429 |
storage=dict(), |
| 430 |
backup=dict(), |
| 431 |
network=dict(), |
| 432 |
high_availability=dict(), |
| 433 |
maintenance_window=dict(), |
| 434 |
source_server_resource_id=item.source_server_resource_id, |
| 435 |
point_in_time_utc=item.point_in_time_utc, |
| 436 |
availability_zone=item.availability_zone, |
| 437 |
auth_config=dict() |
| 438 |
) |
| 439 |
if item.sku is not None: |
| 440 |
result['sku']['name'] = item.sku.name |
| 441 |
result['sku']['tier'] = item.sku.tier |
| 442 |
if item.system_data is not None: |
| 443 |
result['system_data']['created_by'] = item.system_data.created_by |
| 444 |
result['system_data']['created_by_type'] = item.system_data.created_by_type |
| 445 |
result['system_data']['created_at'] = item.system_data.created_at |
| 446 |
result['system_data']['last_modified_by'] = item.system_data.last_modified_by |
| 447 |
result['system_data']['last_modified_by_type'] = item.system_data.last_modified_by_type |
| 448 |
result['system_data']['last_modified_at'] = item.system_data.last_modified_at |
| 449 |
if item.storage is not None: |
| 450 |
result['storage']['storage_size_gb'] = item.storage.storage_size_gb |
| 451 |
if item.backup is not None: |
| 452 |
result['backup']['backup_retention_days'] = item.backup.backup_retention_days |
| 453 |
result['backup']['geo_redundant_backup'] = item.backup.geo_redundant_backup |
| 454 |
if item.network is not None: |
| 455 |
result['network']['public_network_access'] = item.network.public_network_access |
| 456 |
result['network']['delegated_subnet_resource_id'] = item.network.delegated_subnet_resource_id |
| 457 |
result['network']['private_dns_zone_arm_resource_id'] = item.network.private_dns_zone_arm_resource_id |
| 458 |
if item.high_availability is not None: |
| 459 |
result['high_availability']['mode'] = item.high_availability.mode |
| 460 |
result['high_availability']['standby_availability_zone'] = item.high_availability.standby_availability_zone |
| 461 |
if item.maintenance_window is not None: |
| 462 |
result['maintenance_window']['custom_window'] = item.maintenance_window.custom_window |
| 463 |
result['maintenance_window']['start_minute'] = item.maintenance_window.start_minute |
| 464 |
result['maintenance_window']['start_hour'] = item.maintenance_window.start_hour |
| 465 |
result['maintenance_window']['day_of_week'] = item.maintenance_window.day_of_week |
| 466 |
if item.identity is not None: |
| 467 |
result['identity'] = item.identity.as_dict() |
| 468 |
else: |
| 469 |
result['identity'] = PostgreSQLFlexibleModels.UserAssignedIdentity(type='None').as_dict() |
| 470 |
if item.auth_config: |
| 471 |
result['auth_config']['active_directory_auth'] = item.auth_config.active_directory_auth |
| 472 |
result['auth_config']['password_auth'] = item.auth_config.password_auth |
| 473 |
result['auth_config']['tenant_id'] = item.auth_config.tenant_id |
| 474 |
|
| 475 |
return result |
| 476 |
|
| 477 |
|
| 478 |
def main(): |
| 479 |
AzureRMPostgreSqlFlexibleServersInfo() |
| 480 |
|
| 481 |
|
| 482 |
if __name__ == '__main__': |
| 483 |
main() |