diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index cf62b026a5580c7771e4982a13788019854e41e3..92955d516e13b38e52c232b2d9eec3334f592819 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -377,8 +377,17 @@ else: return api.env.realm def gen_add_del_lists(user_list, res_list): - """Generate the lists for the addition and removal of members.""" - # The user list is None, therefore the parameter should not be touched + """ + Generate the lists for the addition and removal of members. + + This function should be used to apply a new user list as a set + operation without action: members. + + For the addition of new and the removal of existing members with + action: members gen_add_list and gen_intersection_list should + be used. + """ + # The user list is None, no need to do anything, return empty lists if user_list is None: return [], [] @@ -387,6 +396,38 @@ else: return add_list, del_list + def gen_add_list(user_list, res_list): + """ + Generate add list for addition of new members. + + This function should be used to add new members with action: members + and state: present. + + It is returning the difference of the user and res list if the user + list is not None. + """ + # The user list is None, no need to do anything, return empty list + if user_list is None: + return [] + + return list(set(user_list or []) - set(res_list or [])) + + def gen_intersection_list(user_list, res_list): + """ + Generate the intersection list for removal of existing members. + + This function should be used to remove existing members with + action: members and state: absent. + + It is returning the intersection of the user and res list if the + user list is not None. + """ + # The user list is None, no need to do anything, return empty list + if user_list is None: + return [] + + return list(set(res_list or []).intersection(set(user_list or []))) + def encode_certificate(cert): """ Encode a certificate using base64.