blob: 6ec3c3c1618d3f29d8dbe2bf91f1c6db08224f51 [file] [log] [blame]
# Copyright (c) 2023 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.
- name: Get the Kuberentes service for Percona XtraDB Cluster
run_once: true
kubernetes.core.k8s_info:
kind: Service
name: "{{ openstack_helm_endpoints.oslo_db.hosts.default }}"
namespace: "{{ migrate_db_from_osa_pxc_namespace }}"
register: _pxc_service
- name: Fail if the databases already exist
run_once: true
check_mode: true
delegate_to: "{{ groups[migrate_db_from_osa_galera_group][0] }}"
community.mysql.mysql_db:
login_host: "{{ _pxc_service.resources[0].spec.clusterIP }}"
login_user: root
login_password: "{{ openstack_helm_endpoints.oslo_db.auth.admin.password }}"
name: "{{ item.value }}"
register: _pxc_db_check
failed_when: _pxc_db_check is not changed
loop: "{{ migrate_db_from_osa_databases | dict2items }}"
- name: Shut off all the containers
run_once: true
delegate_to: "{{ hostvars[item]['physical_host'] }}"
ansible.builtin.command: "lxc-stop -n {{ item }}"
loop: "{{ groups[migrate_db_from_osa_containers_group] }}"
register: _lxc_stop
changed_when: _lxc_stop.rc == 0
failed_when: _lxc_stop.rc != 0 and 'is not running' not in _lxc_stop.stderr
- name: Wait for the containers to stop
run_once: true
delegate_to: "{{ hostvars[item]['physical_host'] }}"
ansible.builtin.wait_for:
path: "/var/lib/lxc/{{ item }}/state"
state: absent
loop: "{{ groups[migrate_db_from_osa_containers_group] }}"
- name: Dump the database
run_once: true
delegate_to: "{{ groups[migrate_db_from_osa_galera_group][0] }}"
community.mysql.mysql_db:
state: dump
name: "{{ item.key }}"
dump_extra_args: --skip_add_locks
skip_lock_tables: true
target: "/root/{{ item.key }}-{{ ansible_date_time.epoch }}.sql"
loop: "{{ migrate_db_from_osa_databases | dict2items }}"
- name: Restore the database
run_once: true
delegate_to: "{{ groups[migrate_db_from_osa_galera_group][0] }}"
community.mysql.mysql_db:
login_host: "{{ _pxc_service.resources[0].spec.clusterIP }}"
login_user: root
login_password: "{{ openstack_helm_endpoints.oslo_db.auth.admin.password }}"
state: import
name: "{{ item.value }}"
target: "/root/{{ item.key }}-{{ ansible_date_time.epoch }}.sql"
loop: "{{ migrate_db_from_osa_databases | dict2items }}"