ovh_instance_playbooks/tasks/deploy_mysql-server.yml

96 lines
3.2 KiB
YAML

---
- name: Stop container service
ansible.builtin.systemd:
name: container-mysql-server
state: stopped
become: true
register: result_mysql_server_systemd_stop
failed_when: "result_mysql_server_systemd_stop is failed and 'Could not find the requested service' not in result_mysql_server_systemd_stop.msg"
- name: Check if mysql-server container is running
command: 'podman ps -q --filter "name=mysql-server"'
changed_when: false
register: podman_ps
become: true
- name: Assert that no mysql-server container is running
ansible.builtin.assert:
that:
- podman_ps.stdout_lines | length == 0
- name: Check if restore from backup is already done
stat:
path: /mnt/volumes/restore_states/mysql_restored
register: mysql_restored_flag
- name: Include tasks/mysql-server_install_from_backup_stage_1.yml
ansible.builtin.include_tasks: "tasks/mysql-server_install_from_backup_stage_1.yml"
when: not mysql_restored_flag.stat.exists
- name: Include tasks/mysql-server_install_from_backup_stage_2.yml
ansible.builtin.include_tasks: "tasks/mysql-server_install_from_backup_stage_2.yml"
when: not mysql_restored_flag.stat.exists
# podman logout is needed before podman login if registry was recreated
- name: Logout from {{ private_registry_domain }}
containers.podman.podman_logout:
registry: "{{ private_registry_domain }}"
changed_when: false
# We ignore failures because the image should be in the cache
failed_when: false
become: true
- name: Login to {{ private_registry_domain }} and create ${XDG_RUNTIME_DIR}/containers/auth.json
containers.podman.podman_login:
username: "{{ private_registry_user }}"
password: "{{ private_registry_password }}"
registry: "{{ private_registry_domain }}"
changed_when: false
# We ignore failures because the image should be in the cache
failed_when: false
become: true
- name: Create mysql-server container
containers.podman.podman_container:
name: mysql-server
image: "{{ private_registry_domain }}/mysql-server:fc2f81452f"
state: present
network:
- mysqlnet
volume:
- /mnt/volumes/mysql-server_data/data:/var/lib/mysql:z
- /mnt/volumes/mysql-server_dumps/data:/mnt/dumps:z
- /mnt/volumes/mysql-server_scripts:/mnt/mysql-server_scripts:z
- /usr/local/docker-mounted-files/docker-mysql-server-stack/debian.cnf:/etc/mysql/debian.cnf:z
generate_systemd:
path: /etc/systemd/system
register: create_mysql_container
become: true
- name: start/enable container service
ansible.builtin.systemd:
daemon-reload: true
name: container-mysql-server
state: started
enabled: true
become: true
- name: Include tasks/mysql-server_install_from_backup_stage_3.yml
ansible.builtin.include_tasks: "tasks/mysql-server_install_from_backup_stage_3.yml"
when: not mysql_restored_flag.stat.exists
- name: mariadb-upgrade
containers.podman.podman_container_exec:
name: mysql-server
command: "bash -c 'mariadb-upgrade --force -u root -p{{ mysql_root_ovh1.password }}'"
become: true
when: create_mysql_container is changed
- name: restart mysql-server
ansible.builtin.systemd:
name: container-mysql-server
state: restarted
become: true
when: create_mysql_container is changed