mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add Description parameter in os_user
Fixes #18914 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
45f07fdeae
commit
da6f6d27e8
2 changed files with 53 additions and 25 deletions
|
@ -55,6 +55,10 @@ options:
|
||||||
- Email address for the user
|
- Email address for the user
|
||||||
required: false
|
required: false
|
||||||
default: None
|
default: None
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- Description about the user
|
||||||
|
version_added: "2.4"
|
||||||
default_project:
|
default_project:
|
||||||
description:
|
description:
|
||||||
- Project name or ID that the user should be associated with by default
|
- Project name or ID that the user should be associated with by default
|
||||||
|
@ -147,11 +151,14 @@ try:
|
||||||
HAS_SHADE = True
|
HAS_SHADE = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_SHADE = False
|
HAS_SHADE = False
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs
|
||||||
|
|
||||||
|
|
||||||
def _needs_update(params_dict, user):
|
def _needs_update(params_dict, user):
|
||||||
for k, v in params_dict.items():
|
for k in params_dict:
|
||||||
if k not in ('password', 'update_password') and user[k] != v:
|
if k not in ('password', 'update_password') and user[k] != params_dict[k]:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# We don't get password back in the user object, so assume any supplied
|
# We don't get password back in the user object, so assume any supplied
|
||||||
|
@ -162,6 +169,7 @@ def _needs_update(params_dict, user):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _get_domain_id(cloud, domain):
|
def _get_domain_id(cloud, domain):
|
||||||
try:
|
try:
|
||||||
# We assume admin is passing domain id
|
# We assume admin is passing domain id
|
||||||
|
@ -177,6 +185,7 @@ def _get_domain_id(cloud, domain):
|
||||||
|
|
||||||
return domain_id
|
return domain_id
|
||||||
|
|
||||||
|
|
||||||
def _get_default_project_id(cloud, default_project, module):
|
def _get_default_project_id(cloud, default_project, module):
|
||||||
project = cloud.get_project(default_project)
|
project = cloud.get_project(default_project)
|
||||||
if not project:
|
if not project:
|
||||||
|
@ -184,18 +193,18 @@ def _get_default_project_id(cloud, default_project, module):
|
||||||
|
|
||||||
return project['id']
|
return project['id']
|
||||||
|
|
||||||
def main():
|
|
||||||
|
|
||||||
|
def main():
|
||||||
argument_spec = openstack_full_argument_spec(
|
argument_spec = openstack_full_argument_spec(
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
password=dict(required=False, default=None, no_log=True),
|
password=dict(required=False, default=None, no_log=True),
|
||||||
email=dict(required=False, default=None),
|
email=dict(required=False, default=None),
|
||||||
default_project=dict(required=False, default=None),
|
default_project=dict(required=False, default=None),
|
||||||
|
description=dict(type='str'),
|
||||||
domain=dict(required=False, default=None),
|
domain=dict(required=False, default=None),
|
||||||
enabled=dict(default=True, type='bool'),
|
enabled=dict(default=True, type='bool'),
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present']),
|
||||||
update_password=dict(default='always', choices=['always',
|
update_password=dict(default='always', choices=['always', 'on_create']),
|
||||||
'on_create']),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
module_kwargs = openstack_module_kwargs()
|
module_kwargs = openstack_module_kwargs()
|
||||||
|
@ -214,6 +223,10 @@ def main():
|
||||||
enabled = module.params['enabled']
|
enabled = module.params['enabled']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
update_password = module.params['update_password']
|
update_password = module.params['update_password']
|
||||||
|
description = module.params['description']
|
||||||
|
|
||||||
|
if description and StrictVersion(shade.__version__) < StrictVersion('1.13.0'):
|
||||||
|
module.fail_json(msg="To utilize description, the installed version of the shade library MUST be >=1.13.0")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cloud = shade.openstack_cloud(**module.params)
|
cloud = shade.openstack_cloud(**module.params)
|
||||||
|
@ -227,14 +240,19 @@ def main():
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if update_password in ('always', 'on_create'):
|
if update_password in ('always', 'on_create'):
|
||||||
if not password:
|
if not password:
|
||||||
msg = ("update_password is %s but a password value is "
|
msg = "update_password is %s but a password value is missing" % update_password
|
||||||
"missing") % update_password
|
|
||||||
module.fail_json(msg=msg)
|
module.fail_json(msg=msg)
|
||||||
default_project_id = None
|
default_project_id = None
|
||||||
if default_project:
|
if default_project:
|
||||||
default_project_id = _get_default_project_id(cloud, default_project, module)
|
default_project_id = _get_default_project_id(cloud, default_project, module)
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
|
if description is not None:
|
||||||
|
user = cloud.create_user(
|
||||||
|
name=name, password=password, email=email,
|
||||||
|
default_project=default_project_id, domain_id=domain_id,
|
||||||
|
enabled=enabled, description=description)
|
||||||
|
else:
|
||||||
user = cloud.create_user(
|
user = cloud.create_user(
|
||||||
name=name, password=password, email=email,
|
name=name, password=password, email=email,
|
||||||
default_project=default_project_id, domain_id=domain_id,
|
default_project=default_project_id, domain_id=domain_id,
|
||||||
|
@ -244,6 +262,8 @@ def main():
|
||||||
params_dict = {'email': email, 'enabled': enabled,
|
params_dict = {'email': email, 'enabled': enabled,
|
||||||
'password': password,
|
'password': password,
|
||||||
'update_password': update_password}
|
'update_password': update_password}
|
||||||
|
if description is not None:
|
||||||
|
params_dict['description'] = description
|
||||||
if domain_id is not None:
|
if domain_id is not None:
|
||||||
params_dict['domain_id'] = domain_id
|
params_dict['domain_id'] = domain_id
|
||||||
if default_project_id is not None:
|
if default_project_id is not None:
|
||||||
|
@ -251,10 +271,22 @@ def main():
|
||||||
|
|
||||||
if _needs_update(params_dict, user):
|
if _needs_update(params_dict, user):
|
||||||
if update_password == 'always':
|
if update_password == 'always':
|
||||||
|
if description is not None:
|
||||||
|
user = cloud.update_user(
|
||||||
|
user['id'], password=password, email=email,
|
||||||
|
default_project=default_project_id,
|
||||||
|
domain_id=domain_id, enabled=enabled, description=description)
|
||||||
|
else:
|
||||||
user = cloud.update_user(
|
user = cloud.update_user(
|
||||||
user['id'], password=password, email=email,
|
user['id'], password=password, email=email,
|
||||||
default_project=default_project_id,
|
default_project=default_project_id,
|
||||||
domain_id=domain_id, enabled=enabled)
|
domain_id=domain_id, enabled=enabled)
|
||||||
|
else:
|
||||||
|
if description is not None:
|
||||||
|
user = cloud.update_user(
|
||||||
|
user['id'], email=email,
|
||||||
|
default_project=default_project_id,
|
||||||
|
domain_id=domain_id, enabled=enabled, description=description)
|
||||||
else:
|
else:
|
||||||
user = cloud.update_user(
|
user = cloud.update_user(
|
||||||
user['id'], email=email,
|
user['id'], email=email,
|
||||||
|
@ -267,18 +299,15 @@ def main():
|
||||||
|
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
if user is None:
|
if user is None:
|
||||||
changed=False
|
changed = False
|
||||||
else:
|
else:
|
||||||
cloud.delete_user(user['id'])
|
cloud.delete_user(user['id'])
|
||||||
changed=True
|
changed = True
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
except shade.OpenStackCloudException as e:
|
except shade.OpenStackCloudException as e:
|
||||||
module.fail_json(msg=str(e), extra_data=e.extra_data)
|
module.fail_json(msg=str(e), extra_data=e.extra_data)
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
from ansible.module_utils.openstack import *
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -150,7 +150,6 @@ lib/ansible/modules/cloud/openstack/os_server_volume.py
|
||||||
lib/ansible/modules/cloud/openstack/os_stack.py
|
lib/ansible/modules/cloud/openstack/os_stack.py
|
||||||
lib/ansible/modules/cloud/openstack/os_subnet.py
|
lib/ansible/modules/cloud/openstack/os_subnet.py
|
||||||
lib/ansible/modules/cloud/openstack/os_subnets_facts.py
|
lib/ansible/modules/cloud/openstack/os_subnets_facts.py
|
||||||
lib/ansible/modules/cloud/openstack/os_user.py
|
|
||||||
lib/ansible/modules/cloud/openstack/os_user_facts.py
|
lib/ansible/modules/cloud/openstack/os_user_facts.py
|
||||||
lib/ansible/modules/cloud/openstack/os_user_group.py
|
lib/ansible/modules/cloud/openstack/os_user_group.py
|
||||||
lib/ansible/modules/cloud/openstack/os_user_role.py
|
lib/ansible/modules/cloud/openstack/os_user_role.py
|
||||||
|
|
Loading…
Reference in a new issue