diff --git a/changelogs/fragments/10955-pritunl_user-null-missing-params.yaml b/changelogs/fragments/10955-pritunl_user-null-missing-params.yaml new file mode 100644 index 0000000000..03aad70fb3 --- /dev/null +++ b/changelogs/fragments/10955-pritunl_user-null-missing-params.yaml @@ -0,0 +1,2 @@ +bugfixes: + - "pritunl_user - improve resilience when comparing user parameters if remote fields are ``null`` or missing. List parameters (``groups``, ``mac_addresses``) now safely default to empty lists for comparison and avoids ``KeyError`` issues (https://github.com/ansible-collections/community.general/issues/10954, https://github.com/ansible-collections/community.general/pull/10955)." diff --git a/plugins/modules/pritunl_user.py b/plugins/modules/pritunl_user.py index c8cc9ea9c6..3a90910ad5 100644 --- a/plugins/modules/pritunl_user.py +++ b/plugins/modules/pritunl_user.py @@ -210,16 +210,18 @@ def add_or_update_pritunl_user(module): for key in user_params.keys(): # When a param is not specified grab existing ones to prevent from changing it with the PUT request if user_params[key] is None: - user_params[key] = users[0][key] + user_params[key] = users[0].get(key) # 'groups' and 'mac_addresses' are list comparison if key == "groups" or key == "mac_addresses": - if set(users[0][key]) != set(user_params[key]): + remote_list = users[0].get(key) or [] + local_list = user_params[key] or [] + if set(remote_list) != set(local_list): user_params_changed = True # otherwise it is either a boolean or a string else: - if users[0][key] != user_params[key]: + if users[0].get(key) != user_params[key]: user_params_changed = True # Trigger a PUT on the API to update the current user if settings have changed