diff --git a/changelogs/fragments/2-info_add_all_settings_profiles.yml b/changelogs/fragments/2-info_add_all_settings_profiles.yml new file mode 100644 index 0000000..48d191e --- /dev/null +++ b/changelogs/fragments/2-info_add_all_settings_profiles.yml @@ -0,0 +1,2 @@ +minor_changes: +- clickhouse_info - add the ``settings_profile_elements`` returns all settings for users, profiles and roles. diff --git a/plugins/modules/clickhouse_info.py b/plugins/modules/clickhouse_info.py index 611ce06..81c0c7e 100644 --- a/plugins/modules/clickhouse_info.py +++ b/plugins/modules/clickhouse_info.py @@ -168,6 +168,13 @@ type: dict sample: { "roles": {"..."}, "users": {"..."} } version_added: '0.7.0' +settings_profile_elements: + description: + - The content of the system.settings_profile_elements table for users, roles, profiles as keys. + returned: success + type: dict + sample: { "roles": {"..."}, "users": {"..."}, "profiles": {"..."} } + version_added: '0.7.0' ''' from ansible.module_utils.basic import AnsibleModule @@ -581,6 +588,53 @@ def get_all_grants(module, client): return grants_info +def get_settings_profile_elements(module, client): + """Get settings_profile_elements. + + Returns a dictionary with roles, profiles and users names as keys. + """ + query = ("SELECT profile_name, user_name, role_name, " + "index, setting_name, value, min, max, " + "inherit_profile FROM system.settings_profile_elements") + result = execute_query(module, client, query) + + if result == PRIV_ERR_CODE: + return {PRIV_ERR_CODE: "Not enough privileges"} + + settings_profile_elements = {'profiles': {}, + 'users': {}, + 'roles': {}, + } + + for row in result: + if row[0] is not None: + dict_name = 'profiles' + name = row[0] + if row[0] not in settings_profile_elements[dict_name]: + settings_profile_elements[dict_name][name] = [] + elif row[1] is not None: + dict_name = 'users' + name = row[1] + if row[1] not in settings_profile_elements[dict_name]: + settings_profile_elements[dict_name][name] = [] + else: + dict_name = 'roles' + name = row[2] + if row[2] not in settings_profile_elements[dict_name]: + settings_profile_elements[dict_name][name] = [] + + settings_profile_elements[dict_name][name].append({ + "index": row[3], + "setting_name": row[4], + "value": row[5], + "min": row[6], + "max": row[7], + "inherit_profile": row[8], + }) + + return settings_profile_elements + + def get_functions(module, client): """Get functions. @@ -708,6 +762,7 @@ def main(): 'merge_tree_settings': get_merge_tree_settings, 'quotas': get_quotas, 'settings_profiles': get_settings_profiles, + 'settings_profile_elements': get_settings_profile_elements, 'functions': get_functions, 'storage_policies': get_storage_policies, 'grants': get_all_grants, diff --git a/tests/integration/targets/clickhouse_info/tasks/initial.yml b/tests/integration/targets/clickhouse_info/tasks/initial.yml index fe9c590..f424c1d 100644 --- a/tests/integration/targets/clickhouse_info/tasks/initial.yml +++ b/tests/integration/targets/clickhouse_info/tasks/initial.yml @@ -17,6 +17,8 @@ - name: Create user eva community.clickhouse.clickhouse_user: name: eva + settings: + - max_memory_usage = 15000 MIN 15000 MAX 16000 READONLY - name: Grant to INSERT for user eva community.clickhouse.clickhouse_client: @@ -58,6 +60,8 @@ - result["settings_profiles"]["default"] != {} - result["storage_policies"] != {} - result["grants"]["users"]["eva"][0]["access_type"] == "INSERT" + - result["settings_profile_elements"]["users"]["eva"][0]["setting_name"] == "max_memory_usage" + - result["settings_profile_elements"]["users"]["eva"][0]["value"] == "15000" - name: Debug ansible.builtin.debug: