Refactored identity_role{,_info} modules

Change-Id: If8230eb8b41b5461e1eaa470569030e8a888015b
This commit is contained in:
Jakob Meng
2023-01-13 11:18:52 +01:00
parent 8534990840
commit 4a27306440
6 changed files with 197 additions and 243 deletions

View File

@@ -4,72 +4,66 @@
# Copyright (c) 2020, Sagi Shnaidman <sshnaidm@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: identity_role_info
short_description: Retrieve information about roles
short_description: Fetch OpenStack identity (Keystone) roles
author: OpenStack Ansible SIG
description:
- Get information about identity roles in Openstack
- Fetch OpenStack identity (Keystone) roles.
options:
domain_id:
description:
- Domain ID which owns the role
- Domain ID which owns the role.
type: str
required: false
name:
description:
- Name or ID of the role
- Name or ID of the role.
type: str
required: false
extends_documentation_fragment:
- openstack.cloud.openstack
'''
RETURN = '''
RETURN = r'''
roles:
description: List of identity roles
description: List of dictionaries describing matching identity roles.
returned: always
type: list
elements: dict
contains:
id:
description: Unique ID for the role
returned: success
type: str
name:
description: Unique role name, within the owning domain.
returned: success
type: str
description:
description: User-facing description of the role.
returned: success
type: str
domain_id:
description: References the domain ID which owns the role.
returned: success
type: str
id:
description: Unique ID for the role
type: str
links:
description: The links for the service resources
returned: success
type: dict
name:
description: Unique role name, within the owning domain.
type: str
'''
EXAMPLES = '''
# Retrieve info about all roles
- openstack.cloud.identity_role_info:
EXAMPLES = r'''
- name: Retrieve info about all roles
openstack.cloud.identity_role_info:
cloud: mycloud
# Retrieve info about all roles in specific domain
- openstack.cloud.identity_role_info:
- name: Retrieve info about all roles in specific domain
openstack.cloud.identity_role_info:
cloud: mycloud
domain_id: some_domain_id
# Retrieve info about role 'admin'
- openstack.cloud.identity_role_info:
- name: Retrieve info about role 'admin'
openstack.cloud.identity_role_info:
cloud: mycloud
name: admin
'''
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
@@ -86,14 +80,17 @@ class IdentityRoleInfoModule(OpenStackModule):
)
def run(self):
params = {
'domain_id': self.params['domain_id'],
'name_or_id': self.params['name'],
}
params = {k: v for k, v in params.items() if v is not None}
kwargs = dict((k, self.params[k])
for k in ['domain_id']
if self.params[k] is not None)
roles = [role.to_dict(computed=False) for role in self.conn.search_roles(**params)]
self.exit_json(changed=False, roles=roles)
name_or_id = self.params['name']
if name_or_id is not None:
kwargs['name_or_id'] = name_or_id
self.exit_json(changed=False,
roles=[r.to_dict(computed=False)
for r in self.conn.search_roles(**kwargs)])
def main():