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/667941 Change-Id: If75b7c3c9367988734b464196fc119e89c65a573
This commit is contained in:
parent
dcdeb98468
commit
a4fa0be21b
41
tasks/db_setup.yml
Normal file
41
tasks/db_setup.yml
Normal 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
|
@ -32,6 +32,38 @@
|
|||||||
tags:
|
tags:
|
||||||
- always
|
- always
|
||||||
|
|
||||||
|
- import_tasks: db_setup.yml
|
||||||
|
when:
|
||||||
|
- inventory_hostname == groups['octavia_all'][0]
|
||||||
|
vars:
|
||||||
|
_oslodb_setup_host: "{{ octavia_db_setup_host }}"
|
||||||
|
_oslodb_databases:
|
||||||
|
- name: "{{ octavia_galera_database }}"
|
||||||
|
users:
|
||||||
|
- username: "{{ octavia_galera_user }}"
|
||||||
|
password: "{{ octavia_container_mysql_password }}"
|
||||||
|
tags:
|
||||||
|
- common-db
|
||||||
|
- octavia-config
|
||||||
|
|
||||||
|
- import_tasks: mq_setup.yml
|
||||||
|
when:
|
||||||
|
- inventory_hostname == groups['octavia_all'][0]
|
||||||
|
vars:
|
||||||
|
_oslomsg_rpc_setup_host: "{{ octavia_oslomsg_rpc_setup_host }}"
|
||||||
|
_oslomsg_rpc_userid: "{{ octavia_oslomsg_rpc_userid }}"
|
||||||
|
_oslomsg_rpc_password: "{{ octavia_oslomsg_rpc_password }}"
|
||||||
|
_oslomsg_rpc_vhost: "{{ octavia_oslomsg_rpc_vhost }}"
|
||||||
|
_oslomsg_rpc_transport: "{{ octavia_oslomsg_rpc_transport }}"
|
||||||
|
_oslomsg_notify_setup_host: "{{ octavia_oslomsg_notify_setup_host }}"
|
||||||
|
_oslomsg_notify_userid: "{{ octavia_oslomsg_notify_userid }}"
|
||||||
|
_oslomsg_notify_password: "{{ octavia_oslomsg_notify_password }}"
|
||||||
|
_oslomsg_notify_vhost: "{{ octavia_oslomsg_notify_vhost }}"
|
||||||
|
_oslomsg_notify_transport: "{{ octavia_oslomsg_notify_transport }}"
|
||||||
|
tags:
|
||||||
|
- common-mq
|
||||||
|
- octavia-config
|
||||||
|
|
||||||
- include_tasks: octavia_certs.yml
|
- include_tasks: octavia_certs.yml
|
||||||
run_once: true
|
run_once: true
|
||||||
when: octavia_generate_certs | bool
|
when: octavia_generate_certs | bool
|
||||||
@ -122,25 +154,7 @@
|
|||||||
- octavia-install
|
- octavia-install
|
||||||
- octavia-config
|
- octavia-config
|
||||||
|
|
||||||
- import_tasks: mq_setup.yml
|
- include_tasks: octavia_db_sync.yml
|
||||||
when:
|
|
||||||
- inventory_hostname == groups['octavia_all'][0]
|
|
||||||
vars:
|
|
||||||
_oslomsg_rpc_setup_host: "{{ octavia_oslomsg_rpc_setup_host }}"
|
|
||||||
_oslomsg_rpc_userid: "{{ octavia_oslomsg_rpc_userid }}"
|
|
||||||
_oslomsg_rpc_password: "{{ octavia_oslomsg_rpc_password }}"
|
|
||||||
_oslomsg_rpc_vhost: "{{ octavia_oslomsg_rpc_vhost }}"
|
|
||||||
_oslomsg_rpc_transport: "{{ octavia_oslomsg_rpc_transport }}"
|
|
||||||
_oslomsg_notify_setup_host: "{{ octavia_oslomsg_notify_setup_host }}"
|
|
||||||
_oslomsg_notify_userid: "{{ octavia_oslomsg_notify_userid }}"
|
|
||||||
_oslomsg_notify_password: "{{ octavia_oslomsg_notify_password }}"
|
|
||||||
_oslomsg_notify_vhost: "{{ octavia_oslomsg_notify_vhost }}"
|
|
||||||
_oslomsg_notify_transport: "{{ octavia_oslomsg_notify_transport }}"
|
|
||||||
tags:
|
|
||||||
- common-mq
|
|
||||||
- octavia-config
|
|
||||||
|
|
||||||
- include_tasks: octavia_db_setup.yml
|
|
||||||
when:
|
when:
|
||||||
- inventory_hostname == groups['octavia_all'][0]
|
- inventory_hostname == groups['octavia_all'][0]
|
||||||
tags:
|
tags:
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
---
|
|
||||||
# Copyright 2017, 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: "{{ octavia_galera_address }}"
|
|
||||||
name: "{{ octavia_galera_database }}"
|
|
||||||
state: "present"
|
|
||||||
delegate_to: "{{ octavia_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: "{{ octavia_galera_address }}"
|
|
||||||
name: "{{ octavia_galera_user }}"
|
|
||||||
password: "{{ octavia_container_mysql_password }}"
|
|
||||||
host: "{{ item }}"
|
|
||||||
state: "present"
|
|
||||||
priv: "{{ octavia_galera_database }}.*:ALL"
|
|
||||||
delegate_to: "{{ octavia_db_setup_host }}"
|
|
||||||
with_items:
|
|
||||||
- "localhost"
|
|
||||||
- "%"
|
|
||||||
no_log: True
|
|
||||||
|
|
||||||
- name: Perform a octavia DB sync
|
|
||||||
command: "{{ octavia_bin }}/octavia-db-manage upgrade head"
|
|
||||||
become: yes
|
|
||||||
become_user: "{{ octavia_system_user_name }}"
|
|
||||||
changed_when: false
|
|
20
tasks/octavia_db_sync.yml
Normal file
20
tasks/octavia_db_sync.yml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
# Copyright 2017, 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 octavia DB sync
|
||||||
|
command: "{{ octavia_bin }}/octavia-db-manage upgrade head"
|
||||||
|
become: yes
|
||||||
|
become_user: "{{ octavia_system_user_name }}"
|
||||||
|
changed_when: false
|
Loading…
Reference in New Issue
Block a user