| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
|
| 9 |
DOCUMENTATION = ''' |
| 10 |
--- |
| 11 |
module: azure_rm_postgresqlflexibleadministrator_info |
| 12 |
version_added: "3.6.0" |
| 13 |
short_description: Get Azure PostgreSQL Flexible Administrator facts |
| 14 |
description: |
| 15 |
- Get facts of PostgreSQL Flexible Administrator. |
| 16 |
|
| 17 |
options: |
| 18 |
resource_group: |
| 19 |
description: |
| 20 |
- The name of the resource group that contains the resource. |
| 21 |
- You can obtain this value from the Azure Resource Manager API or the portal. |
| 22 |
type: str |
| 23 |
required: True |
| 24 |
server_name: |
| 25 |
description: |
| 26 |
- The name of the post gresql server. |
| 27 |
type: str |
| 28 |
required: True |
| 29 |
object_id: |
| 30 |
description: |
| 31 |
- Guid of the objectId for the administrator. |
| 32 |
type: str |
| 33 |
|
| 34 |
extends_documentation_fragment: |
| 35 |
- azure.azcollection.azure |
| 36 |
|
| 37 |
author: |
| 38 |
- magodo (@magodo) |
| 39 |
- xuzhang3 (@xuzhang3) |
| 40 |
- Fred-sun (@Fred-sun) |
| 41 |
|
| 42 |
''' |
| 43 |
|
| 44 |
EXAMPLES = ''' |
| 45 |
- name: List instance of PostgreSQL Flexible Administrator by server name |
| 46 |
azure_rm_postgresqlflexibleadministrator_info: |
| 47 |
resource_group: myResourceGroup |
| 48 |
server_name: server_name |
| 49 |
|
| 50 |
- name: Get instances of PostgreSQL Flexible Administrator |
| 51 |
azure_rm_postgresqlflexibleadministrator_info: |
| 52 |
resource_group: myResourceGroup |
| 53 |
server_name: server_name |
| 54 |
object_id: a2cf7b83-174b-4371-acce-f2381f373641 |
| 55 |
''' |
| 56 |
|
| 57 |
RETURN = ''' |
| 58 |
admistrator: |
| 59 |
description: |
| 60 |
- A list of dictionaries containing facts for PostgreSQL Flexible Administrator. |
| 61 |
returned: always |
| 62 |
type: complex |
| 63 |
contains: |
| 64 |
id: |
| 65 |
description: |
| 66 |
- Resource ID of the postgresql flexible admistrator. |
| 67 |
returned: always |
| 68 |
type: str |
| 69 |
sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/postgresql03/administrators/xxx-xxx" |
| 70 |
principal_name: |
| 71 |
description: |
| 72 |
- Active Directory administrator principal name. |
| 73 |
returned: always |
| 74 |
type: str |
| 75 |
sample: fred-sun |
| 76 |
principal_type: |
| 77 |
description: |
| 78 |
- The principal type used to represent the type of Active Directory Administrator. |
| 79 |
returned: always |
| 80 |
type: str |
| 81 |
sample: User |
| 82 |
object_id: |
| 83 |
description: |
| 84 |
- The Object ID of Azure Directory Administrator. |
| 85 |
returned: always |
| 86 |
type: str |
| 87 |
sample: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 88 |
type: |
| 89 |
description: |
| 90 |
- The type of the resource. |
| 91 |
returned: always |
| 92 |
type: str |
| 93 |
sample: Microsoft.DBforPostgreSQL/flexibleServers/administrators |
| 94 |
tenant_id: |
| 95 |
description: |
| 96 |
- The tenant ID of Active Directory Administrator. |
| 97 |
returned: always |
| 98 |
type: str |
| 99 |
sample: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx |
| 100 |
resource_group: |
| 101 |
description: |
| 102 |
- The resource group name. |
| 103 |
returned: always |
| 104 |
type: str |
| 105 |
sample: testRG |
| 106 |
server_name: |
| 107 |
description: |
| 108 |
- The type of the resource. |
| 109 |
returned: always |
| 110 |
type: str |
| 111 |
sample: postgresql03 |
| 112 |
''' |
| 113 |
|
| 114 |
|
| 115 |
try: |
| 116 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 117 |
from azure.core.exceptions import ResourceNotFoundError |
| 118 |
except ImportError: |
| 119 |
|
| 120 |
pass |
| 121 |
|
| 122 |
|
| 123 |
class AzureRMPostgreSqlFlexibleAdministratorInfo(AzureRMModuleBase): |
| 124 |
def __init__(self): |
| 125 |
|
| 126 |
self.module_arg_spec = dict( |
| 127 |
resource_group=dict( |
| 128 |
type='str', |
| 129 |
required=True |
| 130 |
), |
| 131 |
server_name=dict( |
| 132 |
type='str', |
| 133 |
required=True |
| 134 |
), |
| 135 |
object_id=dict( |
| 136 |
type='str' |
| 137 |
), |
| 138 |
) |
| 139 |
|
| 140 |
self.results = dict( |
| 141 |
changed=False |
| 142 |
) |
| 143 |
self.resource_group = None |
| 144 |
self.object_id = None |
| 145 |
self.server_name = None |
| 146 |
super(AzureRMPostgreSqlFlexibleAdministratorInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True) |
| 147 |
|
| 148 |
def exec_module(self, **kwargs): |
| 149 |
for key in self.module_arg_spec: |
| 150 |
setattr(self, key, kwargs[key]) |
| 151 |
|
| 152 |
if self.object_id: |
| 153 |
self.results['administrators'] = self.get() |
| 154 |
else: |
| 155 |
self.results['administrators'] = self.list_all() |
| 156 |
return self.results |
| 157 |
|
| 158 |
def get(self): |
| 159 |
response = None |
| 160 |
results = [] |
| 161 |
try: |
| 162 |
response = self.postgresql_flexible_client.administrators.get(resource_group_name=self.resource_group, |
| 163 |
server_name=self.server_name, |
| 164 |
object_id=self.object_id) |
| 165 |
self.log("Response : {0}".format(response)) |
| 166 |
except ResourceNotFoundError: |
| 167 |
self.log('Could not get administrator facts for PostgreSQL Flexible Server.') |
| 168 |
|
| 169 |
if response: |
| 170 |
results.append(self.format_item(response)) |
| 171 |
|
| 172 |
return results |
| 173 |
|
| 174 |
def list_all(self): |
| 175 |
response = None |
| 176 |
results = [] |
| 177 |
try: |
| 178 |
response = self.postgresql_flexible_client.administrators.list_by_server(resource_group_name=self.resource_group, |
| 179 |
server_name=self.server_name) |
| 180 |
self.log("Response : {0}".format(response)) |
| 181 |
except Exception as ec: |
| 182 |
self.log('Could not list administrators facts for PostgreSQL Flexible Servers.') |
| 183 |
|
| 184 |
if response: |
| 185 |
for item in response: |
| 186 |
results.append(self.format_item(item)) |
| 187 |
|
| 188 |
return results |
| 189 |
|
| 190 |
def format_item(self, item): |
| 191 |
return dict( |
| 192 |
resource_group=self.resource_group, |
| 193 |
server_name=self.server_name, |
| 194 |
object_id=item.object_id, |
| 195 |
id=item.id, |
| 196 |
principal_name=item.principal_name, |
| 197 |
principal_type=item.principal_type, |
| 198 |
tenant_id=item.tenant_id, |
| 199 |
type=item.type |
| 200 |
) |
| 201 |
|
| 202 |
|
| 203 |
def main(): |
| 204 |
AzureRMPostgreSqlFlexibleAdministratorInfo() |
| 205 |
|
| 206 |
|
| 207 |
if __name__ == '__main__': |
| 208 |
main() |