From ffe31b86387a3ef4e37df004dee84b481009abba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Steinm=C3=BCller?= Date: Mon, 15 Jul 2019 01:07:58 +0000 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. Change-Id: I9073e2d4152a2e0b91e51411d375b2814458e102 --- tasks/db_setup.yml | 40 ++++++++++++++ tasks/main.yml | 52 ++++++++++++------- ...tacker_db_setup.yml => tacker_db_sync.yml} | 26 ---------- 3 files changed, 73 insertions(+), 45 deletions(-) create mode 100644 tasks/db_setup.yml rename tasks/{tacker_db_setup.yml => tacker_db_sync.yml} (53%) diff --git a/tasks/db_setup.yml b/tasks/db_setup.yml new file mode 100644 index 0000000..a2cb43a --- /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/main.yml b/tasks/main.yml index 2abc0b3..f757c46 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -27,6 +27,38 @@ tags: - always +- import_tasks: db_setup.yml + when: + - inventory_hostname == groups['tacker_all'][0] + vars: + _oslodb_setup_host: "{{ tacker_db_setup_host }}" + _oslodb_databases: + - name: "{{ tacker_galera_database }}" + users: + - username: "{{ tacker_galera_user }}" + password: "{{ tacker_container_mysql_password }}" + tags: + - common-db + - tacker-config + +- import_tasks: mq_setup.yml + when: + - inventory_hostname == groups['tacker_all'][0] + vars: + _oslomsg_rpc_setup_host: "{{ tacker_oslomsg_rpc_setup_host }}" + _oslomsg_rpc_userid: "{{ tacker_oslomsg_rpc_userid }}" + _oslomsg_rpc_password: "{{ tacker_oslomsg_rpc_password }}" + _oslomsg_rpc_vhost: "{{ tacker_oslomsg_rpc_vhost }}" + _oslomsg_rpc_transport: "{{ tacker_oslomsg_rpc_transport }}" + _oslomsg_notify_setup_host: "{{ tacker_oslomsg_notify_setup_host }}" + _oslomsg_notify_userid: "{{ tacker_oslomsg_notify_userid }}" + _oslomsg_notify_password: "{{ tacker_oslomsg_notify_password }}" + _oslomsg_notify_vhost: "{{ tacker_oslomsg_notify_vhost }}" + _oslomsg_notify_transport: "{{ tacker_oslomsg_notify_transport }}" + tags: + - common-mq + - tacker-config + - import_tasks: tacker_pre_install.yml tags: - tacker-install @@ -76,25 +108,7 @@ - tacker-install - tacker-config -- import_tasks: mq_setup.yml - when: - - inventory_hostname == groups['tacker_all'][0] - vars: - _oslomsg_rpc_setup_host: "{{ tacker_oslomsg_rpc_setup_host }}" - _oslomsg_rpc_userid: "{{ tacker_oslomsg_rpc_userid }}" - _oslomsg_rpc_password: "{{ tacker_oslomsg_rpc_password }}" - _oslomsg_rpc_vhost: "{{ tacker_oslomsg_rpc_vhost }}" - _oslomsg_rpc_transport: "{{ tacker_oslomsg_rpc_transport }}" - _oslomsg_notify_setup_host: "{{ tacker_oslomsg_notify_setup_host }}" - _oslomsg_notify_userid: "{{ tacker_oslomsg_notify_userid }}" - _oslomsg_notify_password: "{{ tacker_oslomsg_notify_password }}" - _oslomsg_notify_vhost: "{{ tacker_oslomsg_notify_vhost }}" - _oslomsg_notify_transport: "{{ tacker_oslomsg_notify_transport }}" - tags: - - common-mq - - tacker-config - -- import_tasks: tacker_db_setup.yml +- import_tasks: tacker_db_sync.yml when: - inventory_hostname == groups['tacker_all'][0] tags: diff --git a/tasks/tacker_db_setup.yml b/tasks/tacker_db_sync.yml similarity index 53% rename from tasks/tacker_db_setup.yml rename to tasks/tacker_db_sync.yml index 144a6c9..bcc20d6 100644 --- a/tasks/tacker_db_setup.yml +++ b/tasks/tacker_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: "{{ tacker_galera_address }}" - name: "{{ tacker_galera_database }}" - state: "present" - delegate_to: "{{ tacker_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: "{{ tacker_galera_address }}" - name: "{{ tacker_galera_user }}" - password: "{{ tacker_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ tacker_galera_database }}.*:ALL" - delegate_to: "{{ tacker_db_setup_host }}" - with_items: - - "localhost" - - "%" - no_log: True - - name: Perform a tacker DB sync command: "{{ tacker_bin }}/tacker-db-manage --config-file {{ tacker_etc_dir }}/tacker.conf upgrade head"