Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support no-restart flag for clickhouse_user_files #33

Merged
merged 4 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Documentation/Advanced_Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,37 @@ $ { echo 00-ansible-role-config; echo 99-override-config; echo 9-override-config

</details>

##### User configuration files

You can specify additional user configuration files using the `clickhouse_user_files` variable.

```yaml
clickhouse_user_files:
- file: group_templates/clickhouse/clickhouse-server/users.d/additional_user.yml
no_log: true
no_restart: true
```
There are the following attributes supported:
- `no_restart` - changes of this configuration file will not restart the clickhouse-server (i.e. due to it is known that it is applied on fly)
- `no_log` - do not show diff (ansible option), see [Sensitive data in server configuration directives overrides](#sensitive-data-in-server-configuration-directives-overrides) section for more details

<details>

<summary>templates/group_templates/clickhouse/clickhouse-server/users.d/additional_user.yml.j2</summary>

```yaml
# templates/group_templates/clickhouse/clickhouse-server/users.d/additional_user.yml.j2
users:
additional_user:
password: user_password
profile: default
quota: default
networks:
ip: "::/0"
```

</details>

##### Sensitive data in server configuration directives overrides

In case server or users configuration templates contains sensitive data, e. g. plain passwords,
Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ clickhouse_quotas:

# List for additional user-configuration file to override or extend
# variable based configuration
# - no_log -- do not log the diff (ansible)
# - no_restart -- assume that clickhouse-server restart is not required
clickhouse_user_files: []

#
Expand Down
4 changes: 4 additions & 0 deletions example/clickhouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@
clickhouse_online_configuration_files:
- group_templates/clickhouse/clickhouse-server/config.d/remote_servers.yml
- group_templates/clickhouse/clickhouse-server/config.d/zookeeper.yml
clickhouse_user_files:
- file: group_templates/clickhouse/clickhouse-server/users.d/additional_users.yml
no_log: true
no_restart: true
roles:
- clickhouse
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
users:
additional_user:
password: testpass
profile: default
quota: default
networks:
ip: "::/0"
4 changes: 4 additions & 0 deletions molecule/default/inventory/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ clickhouse_user_files:
- users.d/01-first_test_user.yml
- file: users.d/02-second_test_user.yml
no_log: true
- file: users.d/03-third_test_user.yml
# TODO: properly test that attributes are supported
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for attributes does not work now, but OK, they were never worked so I will merge it as-is

If you will be interested - #34 (this will be very welcome!)

no_log: false
azat marked this conversation as resolved.
Show resolved Hide resolved
no_restart: true

clickhouse_configuration_files:
- config.d/01-merge_tree.yml
Expand Down
6 changes: 6 additions & 0 deletions molecule/default/templates/users.d/03-third_test_user.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
users:
third_test_user:
password: testpass
networks:
ip: "::/0"
2 changes: 1 addition & 1 deletion molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# All configured users created
- query: select count() from system.users
result: 4
result: 5

# Profile applied to user
- query: >
Expand Down
18 changes: 13 additions & 5 deletions tasks/pre_configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@
set_fact:
_user_configs: "{{
_user_configs | default([]) + ((item is mapping) | ternary(
[{'file': item.file, 'no_log': item.no_log | default(False)}],
[{'file': item, 'no_log': False}]
))
}}" # noqa: jinja[spacing]
[{'file': item.file, 'no_log': item.no_log | default(False), 'no_restart': item.no_restart | default(False)}],
[{'file': item, 'no_log': False, 'no_restart': False}]
)) }}" # noqa: jinja[spacing]
loop: "{{ common_user_configs + clickhouse_user_files | default([]) }}"
- name: Deploy clickhouse-server users overrides (requires restart)
template:
Expand All @@ -177,7 +176,16 @@
mode: "u=r,go="
notify: restart-clickhouse
no_log: "{{ item.no_log }}"
loop: "{{ _user_configs }}"
loop: "{{ _user_configs | selectattr('no_restart', 'eq', False) }}"
- name: Deploy clickhouse-server users overrides (without restart)
template:
src: "{{ (item is mapping) | ternary(item.file, item) }}.j2"
dest: "/etc/clickhouse-server/users.d/{{ (item is mapping) | ternary(item.file, item) | basename }}"
owner: clickhouse
group: clickhouse
mode: "u=r,go="
no_log: "{{ item.no_log }}"
loop: "{{ _user_configs | selectattr('no_restart', 'eq', True) }}"
- name: Deploy dictionaries configuration (requires restart)
template:
src: "{{ item }}.j2"
Expand Down
Loading