mysql_role: add argument "members_must_exist" (boolean, default true)

The assertion that the users supplied in the "members" argument exist is only executed when the new argument "members_must_exist" is true, to allow opt-out.
This commit is contained in:
Felix Hamme 2022-05-20 10:52:57 +02:00
commit f5a8bc6044

View file

@ -114,6 +114,13 @@ options:
type: bool type: bool
default: no default: no
members_must_exist:
description:
- When C(yes), the module fails if any user in C(members) does not exist.
- When C(no), users in C(members) which don't exist are simply skipped.
type: bool
default: yes
notes: notes:
- Pay attention that the module runs C(SET DEFAULT ROLE ALL TO) - Pay attention that the module runs C(SET DEFAULT ROLE ALL TO)
all the I(members) passed by default when the state has changed. all the I(members) passed by default when the state has changed.
@ -918,6 +925,7 @@ def main():
detach_members=dict(type='bool', default=False), detach_members=dict(type='bool', default=False),
check_implicit_admin=dict(type='bool', default=False), check_implicit_admin=dict(type='bool', default=False),
set_default_role_all=dict(type='bool', default=True), set_default_role_all=dict(type='bool', default=True),
members_must_exist=dict(type='bool', default=True)
) )
module = AnsibleModule( module = AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
@ -951,6 +959,7 @@ def main():
check_hostname = module.params['check_hostname'] check_hostname = module.params['check_hostname']
db = '' db = ''
set_default_role_all = module.params['set_default_role_all'] set_default_role_all = module.params['set_default_role_all']
members_must_exist = module.params['members_must_exist']
if priv and not isinstance(priv, (str, dict)): if priv and not isinstance(priv, (str, dict)):
msg = ('The "priv" parameter must be str or dict ' msg = ('The "priv" parameter must be str or dict '
@ -1019,6 +1028,7 @@ def main():
if members: if members:
members = normalize_users(module, members, server.is_mariadb()) members = normalize_users(module, members, server.is_mariadb())
if members_must_exist and not detach_members:
server.check_users_in_db(members) server.check_users_in_db(members)
# Main job starts here # Main job starts here