mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix for special case of last element of url (#43354)
* fix for special case of last element of url * improved version * fixed mistake * adding appropriate test * fix problem * just fixed task name
This commit is contained in:
parent
c344a94846
commit
c8fcbdef71
3 changed files with 59 additions and 16 deletions
|
@ -210,6 +210,7 @@ class AzureRMResource(AzureRMModuleBase):
|
|||
self.status_code.append(204)
|
||||
|
||||
if self.url is None:
|
||||
orphan = None
|
||||
rargs = dict()
|
||||
rargs['subscription'] = self.subscription_id
|
||||
rargs['resource_group'] = self.resource_group
|
||||
|
@ -217,16 +218,27 @@ class AzureRMResource(AzureRMModuleBase):
|
|||
rargs['namespace'] = "Microsoft." + self.provider
|
||||
else:
|
||||
rargs['namespace'] = self.provider
|
||||
rargs['type'] = self.resource_type
|
||||
rargs['name'] = self.resource_name
|
||||
|
||||
for i in range(len(self.subresource)):
|
||||
rargs['child_namespace_' + str(i + 1)] = self.subresource[i].get('namespace', None)
|
||||
rargs['child_type_' + str(i + 1)] = self.subresource[i].get('type', None)
|
||||
rargs['child_name_' + str(i + 1)] = self.subresource[i].get('name', None)
|
||||
if self.resource_type is not None and self.resource_name is not None:
|
||||
rargs['type'] = self.resource_type
|
||||
rargs['name'] = self.resource_name
|
||||
for i in range(len(self.subresource)):
|
||||
resource_ns = self.subresource[i].get('namespace', None)
|
||||
resource_type = self.subresource[i].get('type', None)
|
||||
resource_name = self.subresource[i].get('name', None)
|
||||
if resource_type is not None and resource_name is not None:
|
||||
rargs['child_namespace_' + str(i + 1)] = resource_ns
|
||||
rargs['child_type_' + str(i + 1)] = resource_type
|
||||
rargs['child_name_' + str(i + 1)] = resource_name
|
||||
else:
|
||||
orphan = resource_type
|
||||
else:
|
||||
orphan = self.resource_type
|
||||
|
||||
self.url = resource_id(**rargs)
|
||||
|
||||
if orphan is not None:
|
||||
self.url += '/' + orphan
|
||||
query_parameters = {}
|
||||
query_parameters['api-version'] = self.api_version
|
||||
|
||||
|
|
|
@ -152,6 +152,7 @@ class AzureRMResourceFacts(AzureRMModuleBase):
|
|||
base_url=self._cloud_environment.endpoints.resource_manager)
|
||||
|
||||
if self.url is None:
|
||||
orphan = None
|
||||
rargs = dict()
|
||||
rargs['subscription'] = self.subscription_id
|
||||
rargs['resource_group'] = self.resource_group
|
||||
|
@ -159,19 +160,27 @@ class AzureRMResourceFacts(AzureRMModuleBase):
|
|||
rargs['namespace'] = "Microsoft." + self.provider
|
||||
else:
|
||||
rargs['namespace'] = self.provider
|
||||
rargs['type'] = self.resource_type
|
||||
rargs['name'] = self.resource_name
|
||||
|
||||
for i in range(len(self.subresource)):
|
||||
rargs['child_namespace_' + str(i + 1)] = self.subresource[i].get('namespace', None)
|
||||
rargs['child_type_' + str(i + 1)] = self.subresource[i].get('type', None)
|
||||
rargs['child_name_' + str(i + 1)] = self.subresource[i].get('name', None)
|
||||
if self.resource_type is not None and self.resource_name is not None:
|
||||
rargs['type'] = self.resource_type
|
||||
rargs['name'] = self.resource_name
|
||||
for i in range(len(self.subresource)):
|
||||
resource_ns = self.subresource[i].get('namespace', None)
|
||||
resource_type = self.subresource[i].get('type', None)
|
||||
resource_name = self.subresource[i].get('name', None)
|
||||
if resource_type is not None and resource_name is not None:
|
||||
rargs['child_namespace_' + str(i + 1)] = resource_ns
|
||||
rargs['child_type_' + str(i + 1)] = resource_type
|
||||
rargs['child_name_' + str(i + 1)] = resource_name
|
||||
else:
|
||||
orphan = resource_type
|
||||
else:
|
||||
orphan = self.resource_type
|
||||
|
||||
self.url = resource_id(**rargs)
|
||||
|
||||
# this is to fix a problem with resource_id implementation, when resource_name is not specified
|
||||
if self.resource_type is not None and self.resource_name is None:
|
||||
self.url += '/' + self.resource_type
|
||||
if orphan is not None:
|
||||
self.url += '/' + orphan
|
||||
|
||||
self.results['url'] = self.url
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
- name: Prepare random number
|
||||
set_fact:
|
||||
nsgname: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
||||
storageaccountname: "stacc{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
||||
run_once: yes
|
||||
|
||||
- name: Call REST API
|
||||
|
@ -54,7 +55,6 @@
|
|||
assert:
|
||||
that: output.changed
|
||||
|
||||
|
||||
- name: Try to get information about account
|
||||
azure_rm_resource_facts:
|
||||
api_version: '2018-02-01'
|
||||
|
@ -63,3 +63,25 @@
|
|||
resource_type: networksecuritygroups
|
||||
resource_name: "{{ nsgname }}"
|
||||
register: output
|
||||
|
||||
- name: Create storage account for Registry
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ storageaccountname }}"
|
||||
type: Standard_LRS
|
||||
|
||||
- name: Try to storage keys -- special case when subresource part has no name
|
||||
azure_rm_resource:
|
||||
resource_group: "{{ resource_group }}"
|
||||
provider: storage
|
||||
resource_type: storageAccounts
|
||||
resource_name: "{{ storageaccountname }}"
|
||||
subresource:
|
||||
- type: listkeys
|
||||
api_version: '2018-03-01-preview'
|
||||
method: POST
|
||||
register: keys
|
||||
|
||||
- name: Assert that key was returned
|
||||
assert:
|
||||
that: keys['response']['keys'][0]['value'] | length > 0
|
||||
|
|
Loading…
Reference in a new issue