diff --git a/tasks/db_setup.yml b/tasks/db_setup.yml new file mode 100644 index 00000000..cdd8e940 --- /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 362e762f..31bc9d9e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -69,6 +69,48 @@ tags: - always +- import_tasks: db_setup.yml + when: + - "nova_services['nova-conductor']['group'] in group_names" + - "inventory_hostname == ((groups[nova_services['nova-conductor']['group']] | intersect(ansible_play_hosts)) | list)[0]" + vars: + _oslodb_setup_host: "{{ nova_db_setup_host }}" + _oslodb_databases: + - name: "{{ nova_galera_database }}" + users: + - username: "{{ nova_galera_user }}" + password: "{{ nova_container_mysql_password }}" + - name: "{{ nova_api_galera_database }}" + users: + - username: "{{ nova_api_galera_user }}" + password: "{{ nova_api_container_mysql_password }}" + - name: "{{ nova_cell0_database }}" + users: + - username: "{{ nova_api_galera_user }}" + password: "{{ nova_api_container_mysql_password }}" + tags: + - common-db + - nova-config + +- import_tasks: mq_setup.yml + when: + - "nova_services['nova-conductor']['group'] in group_names" + - "inventory_hostname == ((groups[nova_services['nova-conductor']['group']] | intersect(ansible_play_hosts)) | list)[0]" + vars: + _oslomsg_rpc_setup_host: "{{ nova_oslomsg_rpc_setup_host }}" + _oslomsg_rpc_userid: "{{ nova_oslomsg_rpc_userid }}" + _oslomsg_rpc_password: "{{ nova_oslomsg_rpc_password }}" + _oslomsg_rpc_vhost: "{{ nova_oslomsg_rpc_vhost }}" + _oslomsg_rpc_transport: "{{ nova_oslomsg_rpc_transport }}" + _oslomsg_notify_setup_host: "{{ nova_oslomsg_notify_setup_host }}" + _oslomsg_notify_userid: "{{ nova_oslomsg_notify_userid }}" + _oslomsg_notify_password: "{{ nova_oslomsg_notify_password }}" + _oslomsg_notify_vhost: "{{ nova_oslomsg_notify_vhost }}" + _oslomsg_notify_transport: "{{ nova_oslomsg_notify_transport }}" + tags: + - common-mq + - nova-config + - import_tasks: nova_virt_detect.yml when: - nova_virt_type is not defined @@ -107,25 +149,6 @@ tags: - nova-config -- import_tasks: mq_setup.yml - when: - - "nova_services['nova-conductor']['group'] in group_names" - - "inventory_hostname == ((groups[nova_services['nova-conductor']['group']] | intersect(ansible_play_hosts)) | list)[0]" - vars: - _oslomsg_rpc_setup_host: "{{ nova_oslomsg_rpc_setup_host }}" - _oslomsg_rpc_userid: "{{ nova_oslomsg_rpc_userid }}" - _oslomsg_rpc_password: "{{ nova_oslomsg_rpc_password }}" - _oslomsg_rpc_vhost: "{{ nova_oslomsg_rpc_vhost }}" - _oslomsg_rpc_transport: "{{ nova_oslomsg_rpc_transport }}" - _oslomsg_notify_setup_host: "{{ nova_oslomsg_notify_setup_host }}" - _oslomsg_notify_userid: "{{ nova_oslomsg_notify_userid }}" - _oslomsg_notify_password: "{{ nova_oslomsg_notify_password }}" - _oslomsg_notify_vhost: "{{ nova_oslomsg_notify_vhost }}" - _oslomsg_notify_transport: "{{ nova_oslomsg_notify_transport }}" - tags: - - common-mq - - nova-config - - import_tasks: nova_db_setup.yml when: - "nova_services['nova-conductor']['group'] in group_names" diff --git a/tasks/nova_db_setup.yml b/tasks/nova_db_setup.yml index 783b3a02..99ad8dc5 100644 --- a/tasks/nova_db_setup.yml +++ b/tasks/nova_db_setup.yml @@ -13,65 +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: "{{ nova_galera_address }}" - name: "{{ item }}" - state: "present" - delegate_to: "{{ nova_db_setup_host }}" - no_log: True - with_items: - - "{{ nova_galera_database }}" - - "{{ nova_api_galera_database }}" - - "{{ nova_cell0_database }}" - -- name: Grant access to DBs for the services - mysql_user: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "{{ nova_galera_address }}" - name: "{{ item['name'] }}" - password: "{{ item['password'] }}" - host: "{{ item['host'] }}" - state: "present" - priv: "{{ item['database'] }}.*:ALL" - append_privs: "{{ item['db_append_privs'] | default(omit) }}" - delegate_to: "{{ nova_db_setup_host }}" - with_items: - - name: "{{ nova_galera_user }}" - password: "{{ nova_container_mysql_password }}" - host: "localhost" - database: "{{ nova_galera_database }}" - db_append_privs: "yes" - - name: "{{ nova_galera_user }}" - password: "{{ nova_container_mysql_password }}" - host: "%" - database: "{{ nova_galera_database }}" - db_append_privs: "yes" - - name: "{{ nova_api_galera_user }}" - password: "{{ nova_api_container_mysql_password }}" - host: "localhost" - database: "{{ nova_api_galera_database }}" - db_append_privs: "yes" - - name: "{{ nova_api_galera_user }}" - password: "{{ nova_api_container_mysql_password }}" - host: "%" - database: "{{ nova_api_galera_database }}" - db_append_privs: "yes" - - name: "{{ nova_api_galera_user }}" - password: "{{ nova_api_container_mysql_password }}" - host: "localhost" - database: "{{ nova_cell0_database }}" - db_append_privs: "yes" - - name: "{{ nova_api_galera_user }}" - password: "{{ nova_api_container_mysql_password }}" - host: "%" - database: "{{ nova_cell0_database }}" - db_append_privs: "yes" - no_log: True - - name: Synchronize the nova API DB schema command: "{{ nova_bin }}/nova-manage api_db sync" become: yes