From a9a9488ef277292e90e17db75081e33a2f562d7a Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Fri, 3 May 2019 14:32:52 -0600 Subject: [PATCH] db_setup: refactor database setup to a common file This patch refactors the database creation to db_setup.yml which will eventually be managed by openstack-ansible-tests. This also re-orders the mq_setup to be done earlier so these system level dependencies are ready before service activation. Depends-On: https://review.opendev.org/660558 Change-Id: If3ac6a4e7002740c8409aef6d378d88bc287a9e7 --- tasks/db_setup.yml | 40 +++++++++++++++++++ ...glance_db_setup.yml => glance_db_sync.yml} | 26 ------------ tasks/main.yml | 28 ++++++++++--- 3 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 tasks/db_setup.yml rename tasks/{glance_db_setup.yml => glance_db_sync.yml} (55%) diff --git a/tasks/db_setup.yml b/tasks/db_setup.yml new file mode 100644 index 00000000..a2cb43a0 --- /dev/null +++ b/tasks/db_setup.yml @@ -0,0 +1,40 @@ +--- +# Copyright 2019, VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# WARNING: +# This file is maintained in the openstack-ansible-tests repository. +# https://git.openstack.org/cgit/openstack/openstack-ansible-tests/tree/sync/tasks/db_setup.yml +# If you need to modify this file, update the one in the openstack-ansible-tests +# repository. Once it merges there, the changes will automatically be proposed to +# all the repositories which use it. + +- name: Setup Database Service (MariaDB) + delegate_to: "{{ _oslodb_setup_host }}" + tags: + - common-mariadb + block: + - name: Create database for service + mysql_db: + name: "{{ item.name }}" + loop: "{{ _oslodb_databases }}" + + - name: Grant access to the database for the service + mysql_user: + name: "{{ item.1.username }}" + password: "{{ item.1.password }}" + host: "{{ item.1.host | default('%') }}" + priv: "{{ item.0.name }}.*:{{ item.1.priv | default('ALL') }}" + loop: "{{ _oslodb_databases | subelements('users') }}" + no_log: true diff --git a/tasks/glance_db_setup.yml b/tasks/glance_db_sync.yml similarity index 55% rename from tasks/glance_db_setup.yml rename to tasks/glance_db_sync.yml index c633094d..d9a66e91 100644 --- a/tasks/glance_db_setup.yml +++ b/tasks/glance_db_sync.yml @@ -13,32 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Create DB for service - mysql_db: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "{{ glance_galera_address }}" - name: "{{ glance_galera_database }}" - state: "present" - delegate_to: "{{ glance_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: "{{ glance_galera_address }}" - name: "{{ glance_galera_user }}" - password: "{{ glance_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ glance_galera_database }}.*:ALL" - delegate_to: "{{ glance_db_setup_host }}" - with_items: - - "localhost" - - "%" - no_log: True - - name: Perform a Glance DB sync command: "{{ glance_bin }}/glance-manage db_sync" become: yes diff --git a/tasks/main.yml b/tasks/main.yml index 410d2300..4de09794 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -40,12 +40,19 @@ tags: - always -- import_tasks: glance_install.yml - tags: - - glance-install - -- import_tasks: glance_post_install.yml +- import_tasks: db_setup.yml + when: + - "glance_services['glance-api']['group'] in group_names" + - "inventory_hostname == ((groups[glance_services['glance-api']['group']]| intersect(ansible_play_hosts)) | list)[0]" + vars: + _oslodb_setup_host: "{{ glance_db_setup_host }}" + _oslodb_databases: + - name: "{{ glance_galera_database }}" + users: + - username: "{{ glance_galera_user }}" + password: "{{ glance_container_mysql_password }}" tags: + - common-db - glance-config - import_tasks: mq_setup.yml @@ -67,11 +74,20 @@ - common-mq - glance-config -- import_tasks: glance_db_setup.yml +- import_tasks: glance_install.yml + tags: + - glance-install + +- import_tasks: glance_post_install.yml + tags: + - glance-config + +- import_tasks: glance_db_sync.yml when: - "glance_services['glance-api']['group'] in group_names" - "inventory_hostname == ((groups[glance_services['glance-api']['group']]| intersect(ansible_play_hosts)) | list)[0]" tags: + - common-db - glance-config - import_tasks: glance_service_setup.yml