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.

We have been using run_once only for keystone role. As we have a
keystone group in the inventory, we re replacing run_once for the
conditionals to match the pattern across all the other roles.

Change-Id: Idb5ea861a87fe077f7c716f1157acd8e39257c5b
This commit is contained in:
Mohammed Naser 2019-05-03 14:37:54 -06:00
parent b638e83354
commit 4ea410ffcd
4 changed files with 77 additions and 46 deletions

View File

@ -468,6 +468,7 @@ keystone_uwsgi_init_overrides: {}
## Service Name-Group Mapping
keystone_services:
keystone-wsgi-public:
group: keystone_all
service_name: "keystone-wsgi-public"
init_config_overrides: "{{ keystone_uwsgi_init_overrides }}"
execstarts: "{{ keystone_uwsgi_bin }}/uwsgi --autoload --ini /etc/uwsgi/keystone-wsgi-public.ini"

41
tasks/db_setup.yml Normal file
View File

@ -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

View File

@ -13,34 +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: "{{ keystone_galera_address }}"
login_port: "{{ keystone_galera_port }}"
name: "{{ keystone_galera_database }}"
state: "present"
delegate_to: "{{ keystone_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: "{{ keystone_galera_address }}"
login_port: "{{ keystone_galera_port }}"
name: "{{ keystone_galera_user }}"
password: "{{ keystone_container_mysql_password }}"
host: "{{ item }}"
state: "present"
priv: "{{ keystone_galera_database }}.*:ALL"
delegate_to: "{{ keystone_db_setup_host }}"
with_items:
- "localhost"
- "%"
no_log: True
- name: Check current state of Keystone DB
command: "{{ keystone_bin }}/keystone-manage db_sync --check"
become: yes

View File

@ -48,6 +48,40 @@
tags:
- always
- import_tasks: db_setup.yml
when:
- "keystone_services['keystone-wsgi-public']['group'] in group_names"
- "inventory_hostname == ((groups[keystone_services['keystone-wsgi-public']['group']] | intersect(ansible_play_hosts)) | list)[0]"
vars:
_oslodb_setup_host: "{{ keystone_db_setup_host }}"
_oslodb_databases:
- name: "{{ keystone_galera_database }}"
users:
- username: "{{ keystone_galera_user }}"
password: "{{ keystone_container_mysql_password }}"
tags:
- common-db
- keystone-config
- import_tasks: mq_setup.yml
when:
- "keystone_services['keystone-wsgi-public']['group'] in group_names"
- "inventory_hostname == ((groups[keystone_services['keystone-wsgi-public']['group']] | intersect(ansible_play_hosts)) | list)[0]"
vars:
_oslomsg_rpc_setup_host: "{{ keystone_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ keystone_oslomsg_rpc_userid }}"
_oslomsg_rpc_password: "{{ keystone_oslomsg_rpc_password }}"
_oslomsg_rpc_vhost: "{{ keystone_oslomsg_rpc_vhost }}"
_oslomsg_rpc_transport: "{{ keystone_oslomsg_rpc_transport }}"
_oslomsg_notify_setup_host: "{{ keystone_oslomsg_notify_setup_host }}"
_oslomsg_notify_userid: "{{ keystone_oslomsg_notify_userid }}"
_oslomsg_notify_password: "{{ keystone_oslomsg_notify_password }}"
_oslomsg_notify_vhost: "{{ keystone_oslomsg_notify_vhost }}"
_oslomsg_notify_transport: "{{ keystone_oslomsg_notify_transport }}"
tags:
- common-mq
- keystone-config
- include_tasks: keystone_pre_install.yml
tags:
- keystone-install
@ -78,7 +112,7 @@
tags:
- keystone-config
- include_tasks: keystone_db_setup.yml
- include_tasks: keystone_db_sync.yml
when:
- "keystone_database_enabled | bool"
tags:
@ -94,23 +128,6 @@
tags:
- keystone-config
- import_tasks: mq_setup.yml
run_once: yes
vars:
_oslomsg_rpc_setup_host: "{{ keystone_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ keystone_oslomsg_rpc_userid }}"
_oslomsg_rpc_password: "{{ keystone_oslomsg_rpc_password }}"
_oslomsg_rpc_vhost: "{{ keystone_oslomsg_rpc_vhost }}"
_oslomsg_rpc_transport: "{{ keystone_oslomsg_rpc_transport }}"
_oslomsg_notify_setup_host: "{{ keystone_oslomsg_notify_setup_host }}"
_oslomsg_notify_userid: "{{ keystone_oslomsg_notify_userid }}"
_oslomsg_notify_password: "{{ keystone_oslomsg_notify_password }}"
_oslomsg_notify_vhost: "{{ keystone_oslomsg_notify_vhost }}"
_oslomsg_notify_transport: "{{ keystone_oslomsg_notify_transport }}"
tags:
- common-mq
- keystone-config
- include_tasks: keystone_ssl.yml
tags:
- keystone-config