Skip to content

Commit 8191e71

Browse files
authored
Merge pull request #231 from igorribeiroduarte/adjust_audit_replication
ansible-scylla-node: Verify if audit is enabled and adjust audit ks
2 parents 8312655 + 8a63c19 commit 8191e71

File tree

3 files changed

+74
-51
lines changed

3 files changed

+74
-51
lines changed

ansible-scylla-node/defaults/main.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,16 @@ scylla_authentication: True
129129
# Set this to false to disable automatic adjustment of system_auth keyspace replication
130130
adjust_system_auth_replication: False
131131

132-
# Replication variables and cql credentials are intended to be used to adjust system_auh keyspace when necessary.
132+
# Set this to false to disable automatic adjustment of audit keyspace replication
133+
adjust_audit_replication: False
134+
135+
# Replication variables and cql credentials are intended to be used to adjust system_auth and audit keyspaces when necessary.
133136
# Remember to update cql credentials here in case you're making updates to an already existing cluster which
134137
# doesn't have the default username/password(cassandra/cassandra)
135138
system_auth_rf: 3
136139
system_auth_replication_strategy: NetworkTopologyStrategy
140+
audit_rf: 3
141+
audit_replication_strategy: NetworkTopologyStrategy
137142
cql_username: cassandra
138143
cql_password: cassandra
139144

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
- name: Validate that all nodes are up before adjusting the replication
3+
uri:
4+
url: "http://{{ scylla_api_address }}:{{ scylla_api_port }}/failure_detector/endpoints/"
5+
follow_redirects: none
6+
method: GET
7+
register: _result
8+
until: _result.status == 200
9+
retries: 10
10+
delay: 1
11+
12+
- name: Get datacenter name
13+
uri:
14+
url: "http://{{ scylla_api_address }}:{{ scylla_api_port }}/snitch/datacenter"
15+
method: GET
16+
register: _datacenter_out
17+
until: _datacenter_out.status == 200
18+
retries: 5
19+
delay: 1
20+
21+
- name: Prepare per DC replication_factor list
22+
set_fact:
23+
dcs_to_rf: "{{ dcs_to_rf | default([]) + [\"'\" + hostvars[item]['_datacenter_out'].json + \"':\" + _keyspace_rf|string] }}"
24+
loop: "{{ groups['scylla'] }}"
25+
run_once: true
26+
27+
- name: Adjust replication for {{ _keyspace }} keyspace
28+
shell: |
29+
cqlsh {{ broadcast_address }} -u {{ cql_username }} -p {{ cql_password }} -e "ALTER KEYSPACE {{ _keyspace }} WITH replication = {'class': '{{ _keyspace_replication_strategy }}', {{ dcs_to_rf | unique | join(',') }}};"
30+
run_once: true
31+
32+
- name: Run cleanup
33+
async_task:
34+
shell: |
35+
nodetool cleanup {{ _keyspace }}
36+
alias: scylla_cleanup
37+
async: "{{ cleanup_timeout_seconds }}"
38+
retries: "{{ cleanup_timeout_seconds // 30 }}" # retries = cleanup_timeout_seconds / delay
39+
delay: 30
40+
register: _cleanup_output
41+
42+
- name: Cleanup logs
43+
debug: var=_cleanup_output
44+
45+
- name: Run repair
46+
include_tasks: repair.yml
47+
vars:
48+
keyspace: '{{ _keyspace }}'

ansible-scylla-node/tasks/common.yml

+20-50
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
when: token_distributor is defined
330330
when: start_scylla_service is defined and start_scylla_service|bool
331331

332-
- name: Check if authentication is enabled
332+
- name: Check if authentication and audit are enabled
333333
block:
334334
- command: cat /etc/scylla/scylla.yaml
335335
ignore_errors: true
@@ -342,62 +342,32 @@
342342
_authentication_enabled: |
343343
{% if (_scylla_yaml_map.authenticator is defined and (_scylla_yaml_map.authenticator == 'TransitionalAuthenticator' or _scylla_yaml_map.authenticator == 'PasswordAuthenticator')) or
344344
(_scylla_yaml_map.authorizer is defined and (_scylla_yaml_map.authorizer == 'TransitionalAuthorizer' or _scylla_yaml_map.authorizer == 'CassandraAuthorizer')) %}True{% else %}False{% endif %}
345+
_audit_enabled: |
346+
{% if (_scylla_yaml_map.audit is defined and _scylla_yaml_map.audit == 'table') %}True{% else %}False{% endif %}
345347
run_once: true
346348

347-
- name: If authentication is enabled, adjust replication for system_auth keyspace
348-
block:
349-
- name: Validate that all nodes are up before adjusting the replication
350-
uri:
351-
url: "http://{{ scylla_api_address }}:{{ scylla_api_port }}/failure_detector/endpoints/"
352-
follow_redirects: none
353-
method: GET
354-
register: _result
355-
until: _result.status == 200
356-
retries: 10
357-
delay: 1
358-
359-
- name: Get datacenter name
360-
uri:
361-
url: "http://{{ scylla_api_address }}:{{ scylla_api_port }}/snitch/datacenter"
362-
method: GET
363-
register: _datacenter_out
364-
until: _datacenter_out.status == 200
365-
retries: 5
366-
delay: 1
367-
368-
- name: Prepare per DC replication_factor list
369-
set_fact:
370-
dcs_to_rf: "{{ dcs_to_rf | default([]) + [\"'\" + hostvars[item]['_datacenter_out'].json + \"':\" + system_auth_rf|string] }}"
371-
loop: "{{ groups['scylla'] }}"
372-
run_once: true
373-
374-
- name: Adjust replication for system_auth keyspace
375-
shell: |
376-
cqlsh {{ broadcast_address }} -u {{ cql_username }} -p {{ cql_password }} -e "ALTER KEYSPACE system_auth WITH replication = {'class': '{{ system_auth_replication_strategy }}', {{ dcs_to_rf | unique | join(',') }}};"
377-
run_once: true
378-
379-
- name: Cleanup system_auth
380-
async_task:
381-
shell: |
382-
nodetool cleanup system_auth
383-
alias: scylla_cleanup_system_auth
384-
async: "{{ cleanup_timeout_seconds }}"
385-
retries: "{{ cleanup_timeout_seconds // 30 }}" # retries = cleanup_timeout_seconds / delay
386-
delay: 30
387-
register: _cleanup_output
388-
389-
- name: Cleanup logs
390-
debug: var=_cleanup_output
391-
392-
- name: Repair system_auth
393-
include_tasks: repair.yml
394-
vars:
395-
keyspace: 'system_auth'
349+
- name: Adjust replication for system_auth keyspace
350+
include_tasks: adjust_keyspace_replication.yml
351+
vars:
352+
_keyspace: "system_auth"
353+
_keyspace_replication_strategy: "{{ system_auth_replication_strategy }}"
354+
_keyspace_rf: "{{ system_auth_rf }}"
396355
when:
397356
- adjust_system_auth_replication is defined and adjust_system_auth_replication|bool
398357
- _authentication_enabled is defined and _authentication_enabled|bool
399358
- system_auth_rf is defined and system_auth_replication_strategy is defined
400359

360+
- name: Adjust replication for audit keyspace
361+
include_tasks: adjust_keyspace_replication.yml
362+
vars:
363+
_keyspace: "audit"
364+
_keyspace_replication_strategy: "{{ audit_replication_strategy }}"
365+
_keyspace_rf: "{{ audit_rf }}"
366+
when:
367+
- adjust_audit_replication is defined and adjust_audit_replication|bool
368+
- _audit_enabled is defined and _audit_enabled|bool
369+
- audit_rf is defined and audit_replication_strategy is defined
370+
401371
- name: generate monitoring configuration
402372
include_tasks: monitoring_config.yml
403373
when: generate_monitoring_config|bool

0 commit comments

Comments
 (0)