From 0475d4218ea9cc5961811b887f5bd77856727331 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotjagov Date: Mon, 24 Jun 2019 15:27:10 +0300 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. Additionally enabling extras repo for centos, since it's not enabled by default but required by docker Change-Id: I441feb4b74b72002af0284137e6025821024979e --- tasks/db_setup.yml | 41 +++++++++++++++++++++++++++++++++++++++ tasks/main.yml | 10 +++++++++- tasks/zun_compute.yml | 1 + tasks/zun_db_setup.yml | 44 ------------------------------------------ 4 files changed, 51 insertions(+), 45 deletions(-) create mode 100644 tasks/db_setup.yml delete mode 100644 tasks/zun_db_setup.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/main.yml b/tasks/main.yml index 97773e8..2380380 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -68,11 +68,19 @@ - common-mq - zun-config -- import_tasks: zun_db_setup.yml +- import_tasks: db_setup.yml + vars: + _oslodb_setup_host: "{{ zun_db_setup_host }}" + _oslodb_databases: + - name: "{{ zun_galera_database }}" + users: + - username: "{{ zun_galera_user }}" + password: "{{ zun_galera_password }}" when: - "zun_services['zun-api']['group'] in group_names" - "inventory_hostname == ((groups['zun_api'] | intersect(ansible_play_hosts)) | list)[0]" tags: + - common-db - zun-config - import_tasks: zun_service_setup.yml diff --git a/tasks/zun_compute.yml b/tasks/zun_compute.yml index 3bf0906..1d7fb3b 100644 --- a/tasks/zun_compute.yml +++ b/tasks/zun_compute.yml @@ -77,6 +77,7 @@ state: "{{ zun_package_state }}" update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" + enablerepo: "{{ (ansible_pkg_mgr == 'yum') | ternary('extras', omit) }}" - name: Generate kuryr config config_template: diff --git a/tasks/zun_db_setup.yml b/tasks/zun_db_setup.yml deleted file mode 100644 index 26faf42..0000000 --- a/tasks/zun_db_setup.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -# Copyright 2018, 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: Run the galera client role - include_role: - name: galera_client - -- name: Create DB for service - mysql_db: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "{{ zun_galera_address }}" - name: "{{ zun_galera_database }}" - state: "present" - delegate_to: "{{ zun_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: "{{ zun_galera_address }}" - name: "{{ zun_galera_user }}" - password: "{{ zun_galera_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ zun_galera_database }}.*:ALL" - delegate_to: "{{ zun_db_setup_host }}" - with_items: - - "localhost" - - "%" - no_log: True