mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fixing facts for mysql server (#45374)
This commit is contained in:
parent
796d8b5dc8
commit
8a221d81dd
3 changed files with 67 additions and 23 deletions
|
@ -82,6 +82,7 @@ options:
|
||||||
|
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- azure
|
- azure
|
||||||
|
- azure_tags
|
||||||
|
|
||||||
author:
|
author:
|
||||||
- "Zim Kalinowski (@zikalino)"
|
- "Zim Kalinowski (@zikalino)"
|
||||||
|
@ -200,20 +201,20 @@ class AzureRMServers(AzureRMModuleBase):
|
||||||
self.resource_group = None
|
self.resource_group = None
|
||||||
self.name = None
|
self.name = None
|
||||||
self.parameters = dict()
|
self.parameters = dict()
|
||||||
|
self.tags = None
|
||||||
|
|
||||||
self.results = dict(changed=False)
|
self.results = dict(changed=False)
|
||||||
self.mgmt_client = None
|
|
||||||
self.state = None
|
self.state = None
|
||||||
self.to_do = Actions.NoAction
|
self.to_do = Actions.NoAction
|
||||||
|
|
||||||
super(AzureRMServers, self).__init__(derived_arg_spec=self.module_arg_spec,
|
super(AzureRMServers, self).__init__(derived_arg_spec=self.module_arg_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
supports_tags=False)
|
supports_tags=True)
|
||||||
|
|
||||||
def exec_module(self, **kwargs):
|
def exec_module(self, **kwargs):
|
||||||
"""Main module execution method"""
|
"""Main module execution method"""
|
||||||
|
|
||||||
for key in list(self.module_arg_spec.keys()):
|
for key in list(self.module_arg_spec.keys()) + ['tags']:
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
setattr(self, key, kwargs[key])
|
setattr(self, key, kwargs[key])
|
||||||
elif kwargs[key] is not None:
|
elif kwargs[key] is not None:
|
||||||
|
@ -243,9 +244,6 @@ class AzureRMServers(AzureRMModuleBase):
|
||||||
old_response = None
|
old_response = None
|
||||||
response = None
|
response = None
|
||||||
|
|
||||||
self.mgmt_client = self.get_mgmt_svc_client(MySQLManagementClient,
|
|
||||||
base_url=self._cloud_environment.endpoints.resource_manager)
|
|
||||||
|
|
||||||
resource_group = self.get_resource_group(self.resource_group)
|
resource_group = self.get_resource_group(self.resource_group)
|
||||||
|
|
||||||
if "location" not in self.parameters:
|
if "location" not in self.parameters:
|
||||||
|
@ -265,6 +263,9 @@ class AzureRMServers(AzureRMModuleBase):
|
||||||
self.to_do = Actions.Delete
|
self.to_do = Actions.Delete
|
||||||
elif self.state == 'present':
|
elif self.state == 'present':
|
||||||
self.log("Need to check if MySQL Server instance has to be deleted or may be updated")
|
self.log("Need to check if MySQL Server instance has to be deleted or may be updated")
|
||||||
|
update_tags, newtags = self.update_tags(old_response.get('tags', {}))
|
||||||
|
if update_tags:
|
||||||
|
self.tags = newtags
|
||||||
self.to_do = Actions.Update
|
self.to_do = Actions.Update
|
||||||
|
|
||||||
if (self.to_do == Actions.Create) or (self.to_do == Actions.Update):
|
if (self.to_do == Actions.Create) or (self.to_do == Actions.Update):
|
||||||
|
@ -315,12 +316,13 @@ class AzureRMServers(AzureRMModuleBase):
|
||||||
self.log("Creating / Updating the MySQL Server instance {0}".format(self.name))
|
self.log("Creating / Updating the MySQL Server instance {0}".format(self.name))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if (self.to_do == Actions.Create):
|
self.parameters['tags'] = self.tags
|
||||||
response = self.mgmt_client.servers.create(resource_group_name=self.resource_group,
|
if self.to_do == Actions.Create:
|
||||||
|
response = self.mysql_client.servers.create(resource_group_name=self.resource_group,
|
||||||
server_name=self.name,
|
server_name=self.name,
|
||||||
parameters=self.parameters)
|
parameters=self.parameters)
|
||||||
else:
|
else:
|
||||||
response = self.mgmt_client.servers.update(resource_group_name=self.resource_group,
|
response = self.mysql_client.servers.update(resource_group_name=self.resource_group,
|
||||||
server_name=self.name,
|
server_name=self.name,
|
||||||
parameters=self.parameters)
|
parameters=self.parameters)
|
||||||
if isinstance(response, LROPoller):
|
if isinstance(response, LROPoller):
|
||||||
|
@ -339,7 +341,7 @@ class AzureRMServers(AzureRMModuleBase):
|
||||||
'''
|
'''
|
||||||
self.log("Deleting the MySQL Server instance {0}".format(self.name))
|
self.log("Deleting the MySQL Server instance {0}".format(self.name))
|
||||||
try:
|
try:
|
||||||
response = self.mgmt_client.servers.delete(resource_group_name=self.resource_group,
|
response = self.mysql_client.servers.delete(resource_group_name=self.resource_group,
|
||||||
server_name=self.name)
|
server_name=self.name)
|
||||||
except CloudError as e:
|
except CloudError as e:
|
||||||
self.log('Error attempting to delete the MySQL Server instance.')
|
self.log('Error attempting to delete the MySQL Server instance.')
|
||||||
|
@ -356,7 +358,7 @@ class AzureRMServers(AzureRMModuleBase):
|
||||||
self.log("Checking if the MySQL Server instance {0} is present".format(self.name))
|
self.log("Checking if the MySQL Server instance {0} is present".format(self.name))
|
||||||
found = False
|
found = False
|
||||||
try:
|
try:
|
||||||
response = self.mgmt_client.servers.get(resource_group_name=self.resource_group,
|
response = self.mysql_client.servers.get(resource_group_name=self.resource_group,
|
||||||
server_name=self.name)
|
server_name=self.name)
|
||||||
found = True
|
found = True
|
||||||
self.log("Response : {0}".format(response))
|
self.log("Response : {0}".format(response))
|
||||||
|
|
|
@ -63,7 +63,13 @@ servers:
|
||||||
- Resource ID
|
- Resource ID
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
sample: /subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforMySQL/servers/myabdud1223
|
sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/TestGroup/providers/Microsoft.DBforMySQL/servers/myabdud1223
|
||||||
|
resource_group:
|
||||||
|
description:
|
||||||
|
- Resource group name.
|
||||||
|
returned: always
|
||||||
|
type: str
|
||||||
|
sample: testresourcegroup
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Resource name.
|
- Resource name.
|
||||||
|
@ -118,6 +124,10 @@ servers:
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
sample: myabdud1223.mys.database.azure.com
|
sample: myabdud1223.mys.database.azure.com
|
||||||
|
tags:
|
||||||
|
description: Tags assigned to the resource. Dictionary of string:string pairs.
|
||||||
|
type: dict
|
||||||
|
sample: { tag1: abc }
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
||||||
|
@ -189,7 +199,7 @@ class AzureRMServersFacts(AzureRMModuleBase):
|
||||||
response = self.mysql_client.servers.list_by_resource_group(resource_group_name=self.resource_group)
|
response = self.mysql_client.servers.list_by_resource_group(resource_group_name=self.resource_group)
|
||||||
self.log("Response : {0}".format(response))
|
self.log("Response : {0}".format(response))
|
||||||
except CloudError as e:
|
except CloudError as e:
|
||||||
self.fail("Error listing for resource group {0} - {1}".format(self.resource_group, str(e)))
|
self.log('Could not get facts for MySQL Servers.')
|
||||||
|
|
||||||
if response is not None:
|
if response is not None:
|
||||||
for item in response:
|
for item in response:
|
||||||
|
@ -211,7 +221,8 @@ class AzureRMServersFacts(AzureRMModuleBase):
|
||||||
'enforce_ssl': (d['ssl_enforcement'] == 'Enabled'),
|
'enforce_ssl': (d['ssl_enforcement'] == 'Enabled'),
|
||||||
'admin_username': d['administrator_login'],
|
'admin_username': d['administrator_login'],
|
||||||
'user_visible_state': d['user_visible_state'],
|
'user_visible_state': d['user_visible_state'],
|
||||||
'fully_qualified_domain_name': d['fully_qualified_domain_name']
|
'fully_qualified_domain_name': d['fully_qualified_domain_name'],
|
||||||
|
'tags': d.get('tags')
|
||||||
}
|
}
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
|
@ -76,11 +76,29 @@
|
||||||
enforce_ssl: True
|
enforce_ssl: True
|
||||||
admin_username: zimxyz
|
admin_username: zimxyz
|
||||||
admin_password: Testpasswordxyz12!
|
admin_password: Testpasswordxyz12!
|
||||||
|
tags:
|
||||||
|
aaa: bbb
|
||||||
|
|
||||||
|
- name: Create second instance of MySQL Server
|
||||||
|
azure_rm_mysqlserver:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: mysqlsrv{{ rpfx }}second
|
||||||
|
sku:
|
||||||
|
name: B_Gen5_1
|
||||||
|
tier: Basic
|
||||||
|
location: westus2
|
||||||
|
storage_mb: 51200
|
||||||
|
version: 5.6
|
||||||
|
enforce_ssl: True
|
||||||
|
admin_username: zimxyz
|
||||||
|
admin_password: Testpasswordxyz12!
|
||||||
|
tags:
|
||||||
|
ccc: ddd
|
||||||
|
|
||||||
- name: Gather facts MySQL Server
|
- name: Gather facts MySQL Server
|
||||||
azure_rm_mysqlserver_facts:
|
azure_rm_mysqlserver_facts:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
name: mysqlsrv{{ rpfx }}
|
name: mysqlsrv{{ rpfx }}second
|
||||||
register: output
|
register: output
|
||||||
|
|
||||||
- name: Assert that facts are returned
|
- name: Assert that facts are returned
|
||||||
|
@ -96,6 +114,8 @@
|
||||||
- output.servers[0]['version'] != None
|
- output.servers[0]['version'] != None
|
||||||
- output.servers[0]['user_visible_state'] != None
|
- output.servers[0]['user_visible_state'] != None
|
||||||
- output.servers[0]['fully_qualified_domain_name'] != None
|
- output.servers[0]['fully_qualified_domain_name'] != None
|
||||||
|
- output.servers[0]['tags']['aaa'] == 'bbb'
|
||||||
|
- output.servers[0]['tags']['ccc'] == 'ddd'
|
||||||
|
|
||||||
- name: Gather facts MySQL Server
|
- name: Gather facts MySQL Server
|
||||||
azure_rm_mysqlserver_facts:
|
azure_rm_mysqlserver_facts:
|
||||||
|
@ -241,8 +261,9 @@
|
||||||
- output.changed == false
|
- output.changed == false
|
||||||
|
|
||||||
#
|
#
|
||||||
# clean up azure_rm_mysqlserver test
|
# azure_rm_mysqlserver continuation / clean up
|
||||||
#
|
#
|
||||||
|
|
||||||
- name: Delete instance of MySQL Server -- check mode
|
- name: Delete instance of MySQL Server -- check mode
|
||||||
azure_rm_mysqlserver:
|
azure_rm_mysqlserver:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
|
@ -271,6 +292,16 @@
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
name: mysqlsrv{{ rpfx }}
|
name: mysqlsrv{{ rpfx }}
|
||||||
state: absent
|
state: absent
|
||||||
|
register: output
|
||||||
|
- name: Assert the state has changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- output.changed == false
|
||||||
|
|
||||||
|
- name: Delete second instance of MySQL Server
|
||||||
|
azure_rm_mysqlserver:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: mysqlsrv{{ rpfx }}second
|
||||||
|
state: absent
|
||||||
async: 400
|
async: 400
|
||||||
poll: 0
|
poll: 0
|
||||||
|
|
Loading…
Reference in a new issue