From f8809b4cab8483c25927e9339f7210e3965f92e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Steinm=C3=BCller?= Date: Mon, 3 Jun 2019 19:43:40 +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: Ibda9982a85b967dac091bdcd0e115b3c6333361b --- tasks/db_setup.yml | 41 +++++++++++++++++++++++++++++++++ tasks/gnocchi_db_setup.yml | 46 -------------------------------------- tasks/gnocchi_db_sync.yml | 20 +++++++++++++++++ tasks/main.yml | 16 ++++++++++++- 4 files changed, 76 insertions(+), 47 deletions(-) create mode 100644 tasks/db_setup.yml delete mode 100644 tasks/gnocchi_db_setup.yml create mode 100644 tasks/gnocchi_db_sync.yml diff --git a/tasks/db_setup.yml b/tasks/db_setup.yml new file mode 100644 index 0000000..cdd8e94 --- /dev/null +++ b/tasks/db_setup.yml @@ -0,0 +1,41 @@ +--- +# 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') }}" + append_privs: yes + loop: "{{ _oslodb_databases | subelements('users') }}" + no_log: true diff --git a/tasks/gnocchi_db_setup.yml b/tasks/gnocchi_db_setup.yml deleted file mode 100644 index 365838c..0000000 --- a/tasks/gnocchi_db_setup.yml +++ /dev/null @@ -1,46 +0,0 @@ ---- -# Copyright 2014, Rackspace US, 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. - -- name: Create DB for service - mysql_db: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "{{ gnocchi_galera_address }}" - name: "{{ gnocchi_galera_database }}" - state: "present" - delegate_to: "{{ gnocchi_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: "{{ gnocchi_galera_address }}" - name: "{{ gnocchi_galera_user }}" - password: "{{ gnocchi_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ gnocchi_galera_database }}.*:ALL" - delegate_to: "{{ gnocchi_db_setup_host }}" - with_items: - - "localhost" - - "%" - no_log: True - -- name: Perform a Gnocchi DB sync - command: "{{ gnocchi_bin }}/gnocchi-upgrade {{ gnocchi_db_sync_options }}" - become: yes - become_user: "{{ gnocchi_system_user_name }}" - changed_when: false diff --git a/tasks/gnocchi_db_sync.yml b/tasks/gnocchi_db_sync.yml new file mode 100644 index 0000000..5f3870b --- /dev/null +++ b/tasks/gnocchi_db_sync.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2014, Rackspace US, 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. + +- name: Perform a Gnocchi DB sync + command: "{{ gnocchi_bin }}/gnocchi-upgrade {{ gnocchi_db_sync_options }}" + become: yes + become_user: "{{ gnocchi_system_user_name }}" + changed_when: false diff --git a/tasks/main.yml b/tasks/main.yml index 77ac519..18df7e1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -25,6 +25,20 @@ tags: - always +- import_tasks: db_setup.yml + when: + - inventory_hostname == groups['gnocchi_all'][0] + vars: + _oslodb_setup_host: "{{ gnocchi_db_setup_host }}" + _oslodb_databases: + - name: "{{ gnocchi_galera_database }}" + users: + - username: "{{ gnocchi_galera_user }}" + password: "{{ gnocchi_container_mysql_password }}" + tags: + - common-db + - gnocchi-config + - import_tasks: gnocchi_pre_install.yml tags: - gnocchi-install @@ -89,7 +103,7 @@ # N.B. Must occur after identity setup, as this may perform calls to Swift. # Similarly, when using Ceph, must occur after Ceph setup. -- import_tasks: gnocchi_db_setup.yml +- import_tasks: gnocchi_db_sync.yml when: - inventory_hostname == groups['gnocchi_all'][0] - not gnocchi_identity_only | bool