mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cs_account: Implement role parameter support (#46166)
This commit is contained in:
parent
ac9d506a61
commit
382641ff24
1 changed files with 29 additions and 1 deletions
|
@ -71,6 +71,10 @@ options:
|
|||
description:
|
||||
- Domain the account is related to.
|
||||
default: 'ROOT'
|
||||
role:
|
||||
description:
|
||||
- Creates the account under the specified role name or id.
|
||||
version_added: 2.8
|
||||
state:
|
||||
description:
|
||||
- State of the account.
|
||||
|
@ -96,6 +100,7 @@ EXAMPLES = '''
|
|||
first_name: John
|
||||
email: john.doe@example.com
|
||||
domain: CUSTOMERS
|
||||
role: Domain Admin
|
||||
|
||||
# Lock an existing account in domain 'CUSTOMERS'
|
||||
- local_action:
|
||||
|
@ -158,6 +163,11 @@ domain:
|
|||
returned: success
|
||||
type: string
|
||||
sample: ROOT
|
||||
role:
|
||||
description: The role name of the account
|
||||
returned: success
|
||||
type: string
|
||||
sample: Domain Admin
|
||||
'''
|
||||
|
||||
# import cloudstack common
|
||||
|
@ -175,6 +185,7 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|||
super(AnsibleCloudStackAccount, self).__init__(module)
|
||||
self.returns = {
|
||||
'networkdomain': 'network_domain',
|
||||
'rolename': 'role',
|
||||
}
|
||||
self.account = None
|
||||
self.account_types = {
|
||||
|
@ -183,6 +194,21 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|||
'domain_admin': 2,
|
||||
}
|
||||
|
||||
def get_role_id(self):
|
||||
role_param = self.module.params.get('role')
|
||||
role_id = None
|
||||
|
||||
if role_param:
|
||||
role_list = self.query_api('listRoles')
|
||||
for role in role_list['role']:
|
||||
if role_param in [role['name'], role['id']]:
|
||||
role_id = role['id']
|
||||
|
||||
if not role_id:
|
||||
self.module.fail_json(msg="Role not found: %s" % role_param)
|
||||
|
||||
return role_id
|
||||
|
||||
def get_account_type(self):
|
||||
account_type = self.module.params.get('account_type')
|
||||
return self.account_types[account_type]
|
||||
|
@ -278,7 +304,8 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
|
|||
'firstname': self.module.params.get('first_name'),
|
||||
'lastname': self.module.params.get('last_name'),
|
||||
'email': self.module.params.get('email'),
|
||||
'timezone': self.module.params.get('timezone')
|
||||
'timezone': self.module.params.get('timezone'),
|
||||
'roleid': self.get_role_id()
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.query_api('createAccount', **args)
|
||||
|
@ -323,6 +350,7 @@ def main():
|
|||
username=dict(),
|
||||
password=dict(no_log=True),
|
||||
timezone=dict(),
|
||||
role=dict(),
|
||||
poll_async=dict(type='bool', default=True),
|
||||
))
|
||||
|
||||
|
|
Loading…
Reference in a new issue