Browse Source

#12 return user detail data if requested

9.0.0-dev
Markus Bergholz 1 year ago
parent
commit
b1c43c6d59
No known key found for this signature in database
GPG Key ID: B45724801354B174
  1. 37
      plugins/modules/user_info.py
  2. 13
      tests/integration/targets/user/tasks/main.yml

37
plugins/modules/user_info.py

@ -13,6 +13,14 @@ description:
version_added: "4.0.0"
author:
- "Markus Bergholz (@markuman)"
options:
username:
description:
- Nextcloud username to receive detail information.
- Nextcloud UserID
required: false
type: str
aliases: ['user_id']
extends_documentation_fragment:
- markuman.nextcloud.nextcloud.connectivity
notes:
@ -20,8 +28,18 @@ notes:
'''
EXAMPLES = '''
- name: install and enable impersonate app
- name: >
user info
returns list of all users
markuman.nextcloud.user_info:
register: out
- name: >
user info detailed
returns details for one requested user
markuman.nextcloud.user_info:
username: some_user
register: out
'''
from ansible.module_utils.basic import AnsibleModule
@ -32,14 +50,23 @@ from ansible_collections.markuman.nextcloud.plugins.module_utils.nextcloud impor
def main():
module = AnsibleModule(
supports_check_mode=True,
argument_spec=parameter_spects({})
argument_spec=parameter_spects(dict(
username=dict(required=False, type='str', aliases=['user_id'])
))
)
nc = NextcloudHandler(module.params)
username = module.params.get('username')
retval = nc.get('/ocs/v1.php/cloud/users').json()
module.exit_json(users=retval.get('ocs', {}).get('data', {}).get('users', []))
if username:
retval = nc.get(f'/ocs/v1.php/cloud/users/{username}').json()
module.exit_json(
users=[username],
user_data=retval.get('ocs', {}).get('data')
)
else:
retval = nc.get('/ocs/v1.php/cloud/users').json()
module.exit_json(users=retval.get('ocs', {}).get('data', {}).get('users', []),user_data={})
if __name__ == '__main__':

13
tests/integration/targets/user/tasks/main.yml

@ -5,4 +5,15 @@
- name: only one user exists
assert:
that:
- out.users |count == 1
- out.users |count == 1
- name: get user details from admin user
markuman.nextcloud.user_info:
username: ansible
register: out
- name: verify admin user
assert:
that:
- "'admin' in out.user_data.groups"
- out.user_data.quota.quota == -3

Loading…
Cancel
Save