From 1976e84796a8c8ae34a159018db907381753ec7c Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Tue, 12 Jun 2018 19:59:24 +0100 Subject: [PATCH] Move database creation into role There is no record for why we implement the database creation outside of the role in the playbook, when we could do it inside the role. Implementing it inside the role allows us to reduce the quantity of group_vars duplicated from the role, and allows us to better document the required variables in the role. The delegation can still be done as it is done in the playbook too. In this patch we implement a new variable called 'blazar_db_setup_host' which is used in the role to allow delegation of the database setup task to any host, but defaults to the first member of the galera_all host group. We also document the variable blazar_galera_address which has been used for a long time, but never documented. A bunch of unused variables have also been removed. Change-Id: Id500e2b2a5b981609becc883edd3d166f70103f4 --- defaults/main.yml | 16 +++++----------- tasks/blazar_db_setup.yml | 28 +++++++++++++++++++++++++++- tests/test-install-blazar.yml | 4 ---- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index fcbcc30..bd9bd58 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -54,12 +54,10 @@ blazar_system_comment: blazar system user blazar_system_user_home: "/var/lib/{{ blazar_system_user_name }}" ## Database credentials -blazar_db_name: blazar -blazar_db_user: root -blazar_db_login_host: "" -blazar_db_login_user: "" -blazar_db_login_password: "" -blazar_db_user_password: "" +blazar_db_setup_host: "{{ ('galera_all' in groups) | ternary(groups['galera_all'][0], 'localhost') }}" +blazar_galera_address: "{{ galera_address | default('127.0.0.1') }}" +blazar_galera_database: blazar +blazar_galera_user: blazar ## Service Type and Data blazar_service_region: RegionOne @@ -97,10 +95,6 @@ blazar_keystone_auth_plugin: password blazar_service_in_ldap: false -## DB info -blazar_galera_database: blazar -blazar_galera_user: blazar - blazar_role_name: admin blazar_bind_address: 0.0.0.0 blazar_service_port: 9800 @@ -108,4 +102,4 @@ blazar_program_name: blazar-server ## Tunable overrides blazar_blazar_api_paste_ini_overrides: {} -blazar_blazar_conf_overrides: {} \ No newline at end of file +blazar_blazar_conf_overrides: {} diff --git a/tasks/blazar_db_setup.yml b/tasks/blazar_db_setup.yml index 346af89..e81a1a3 100644 --- a/tasks/blazar_db_setup.yml +++ b/tasks/blazar_db_setup.yml @@ -14,7 +14,33 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: create blazar database schema +- name: Create DB for service + mysql_db: + login_user: "{{ galera_root_user }}" + login_password: "{{ galera_root_password }}" + login_host: "{{ blazar_galera_address }}" + name: "{{ blazar_galera_database }}" + state: "present" + delegate_to: "{{ blazar_db_setup_host }}" + no_log: True + +- name: Grant access to the DB for the service + mysql_user: + login_user: "{{ galera_root_user }}" + login_password: "{{ galera_root_password }}" + login_host: "{{ blazar_galera_address }}" + name: "{{ blazar_galera_user }}" + password: "{{ blazar_container_mysql_password }}" + host: "{{ item }}" + state: "present" + priv: "{{ blazar_galera_database }}.*:ALL" + delegate_to: "{{ blazar_db_setup_host }}" + with_items: + - "localhost" + - "%" + no_log: True + +- name: Create blazar database schema command: > {{ blazar_bin }}/blazar-db-manage --config-file {{ blazar_conf_dir }}/blazar.conf upgrade head diff --git a/tests/test-install-blazar.yml b/tests/test-install-blazar.yml index cb5a111..dcd0ae9 100644 --- a/tests/test-install-blazar.yml +++ b/tests/test-install-blazar.yml @@ -27,10 +27,6 @@ when: - "groups['rabbitmq_all'] is defined" - - include: common/create-grant-db.yml - db_name: "{{ blazar_galera_database }}" - db_password: "{{ blazar_container_mysql_password }}" - roles: - role: "os_blazar" vars_files: