Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovirt_user: add ssh_public_key #232

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions plugins/modules/ovirt_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
- "Namespace where the user resides. When using the authorization provider that stores users in the LDAP server,
this attribute equals the naming context of the LDAP server."
type: str
ssh_public_key:
description:
- "The user public key."
type: str
extends_documentation_fragment: @NAMESPACE@.@[email protected]
'''

Expand All @@ -76,6 +80,12 @@
state: absent
name: user1
authz_name: example.com-authz

# Remove ssh_public_key
- @NAMESPACE@.@[email protected]_user:
name: user1
authz_name: example.com-authz
ssh_public_key: ""
'''

RETURN = '''
Expand Down Expand Up @@ -134,6 +144,7 @@ def main():
name=dict(required=True),
authz_name=dict(required=True, aliases=['domain']),
namespace=dict(default=None),
ssh_public_key=dict(default=None),
)
module = AnsibleModule(
argument_spec=argument_spec,
Expand All @@ -160,6 +171,20 @@ def main():
'usrname': username(module),
}
)
if module.params['ssh_public_key'] is not None:
ssh_public_keys_service = users_service.user_service(ret['id']).ssh_public_keys_service()
ssh_public_keys = ssh_public_keys_service.list()
if ssh_public_keys:
if not module.params['ssh_public_key']:
ssh_public_keys_service.service(ssh_public_keys[0].id).remove()
ret['changed'] = True
elif module.params['ssh_public_key'] != ssh_public_keys[0].content:
ssh_public_keys_service.service(ssh_public_keys[0].id).update(otypes.SshPublicKey(content=module.params['ssh_public_key']))
ret['changed'] = True
elif module.params['ssh_public_key']:
ssh_public_keys_service.add(otypes.SshPublicKey(content=module.params['ssh_public_key']))
ret['changed'] = True

elif state == 'absent':
ret = users_module.remove(
search_params={
Expand Down