-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve user creation to use default user the first time
Signed-off-by: Jakub Sokołowski <[email protected]>
- Loading branch information
Showing
4 changed files
with
32 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
--- | ||
- name: Check default user connection | ||
set_fact: | ||
echo "DESCRIBE CLUSTER;" | | ||
/opt/cassandra/bin/cqlsh {{ cassandra_listen_address }} \ | ||
-u '{{ cassandra_db_default_user }}' \ | ||
-p '{{ cassandra_db_default_pass }}' | ||
ignore_errors: true | ||
register: default_user_auth | ||
|
||
# If default user is disabled just use first defined user | ||
- name: Pick DB auth credentials to use | ||
set_fact: | ||
cassandra_db_default_user: '{{ cassandra_db_users[0].user }}' | ||
cassandra_db_default_pass: '{{ cassandra_db_users[0].pass }}' | ||
when: default_user_auth.failed | ||
|
||
- name: Create specified DB users | ||
shell: | | ||
echo "CREATE ROLE {{ item.user }} WITH SUPERUSER = true AND LOGIN = true AND PASSWORD = '{{ item.pass }}';" | \ | ||
/opt/cassandra/bin/cqlsh {{ cassandra_listen_address }} -u '{{ item.user }}' -p '{{ item.user }}' | ||
with_items: '{{ cassandra_users }}' | ||
/opt/cassandra/bin/cqlsh {{ cassandra_listen_address }} \ | ||
-u '{{ cassandra_db_default_user }}' \ | ||
-p '{{ cassandra_db_default_pass }}' | ||
with_items: '{{ cassandra_db_users }}' | ||
|
||
- name: Disable default user | ||
shell: | | ||
echo "ALTER ROLE cassandra WITH SUPERUSER = false AND LOGIN = false;" | \ | ||
/opt/cassandra/bin/cqlsh {{ cassandra_listen_address }} -u '{{ item.user }}' -p '{{ item.user }}' | ||
when: '{{ (cassandra_users|length) > 0 }}' | ||
/opt/cassandra/bin/cqlsh {{ cassandra_listen_address }} \ | ||
-u '{{ cassandra_db_users[0].user }}' \ | ||
-p '{{ cassandra_db_users[0].pass }}' | ||
when: '{{ (cassandra_db_users|length) > 0 }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters