225 lines
5.6 KiB
YAML
225 lines
5.6 KiB
YAML
# Review /root/scripts/check-memory.sh --> It's not optimal to do what this program does
|
|
# Also review the cron task /root/scripts/scheduler-log.sh
|
|
|
|
- name: Ensure Install requirements for MariaDB repository setup script
|
|
apt:
|
|
name: "{{ mariadb_requeriments }}"
|
|
state: present
|
|
install_recommends: no
|
|
|
|
- name: Download required setup files
|
|
get_url:
|
|
url: "{{ item.url }}"
|
|
dest: "{{ item.dest }}"
|
|
mode: "{{ item.mode }}"
|
|
loop: "{{ downloads }}"
|
|
|
|
- name: Run MariaDB repository setup script
|
|
command:
|
|
cmd: "/bin/bash /tmp/mariadb_repo_setup --mariadb-server-version=10.11.10"
|
|
creates: "/etc/apt/sources.list.d/mariadb.list"
|
|
|
|
- name: Install Percona repository package
|
|
apt:
|
|
deb: "/tmp/percona-release_latest.generic_all.deb"
|
|
state: present
|
|
install_recommends: no
|
|
|
|
- name: Update apt cache
|
|
apt:
|
|
update_cache: yes
|
|
|
|
- name: Install MariaDB packages
|
|
apt:
|
|
name: "{{ mariadb_base_packages }}"
|
|
state: present
|
|
install_recommends: no
|
|
|
|
- name: Add tmpfs in /etc/fstab
|
|
blockinfile:
|
|
path: /etc/fstab
|
|
marker: "# {mark} ANSIBLE-MANAGED TMPFS ENTRY"
|
|
block: |
|
|
tmpfs /mnt/mysqltmp tmpfs rw,size={{ mysqltmpsize }} 0 0
|
|
register: fstab
|
|
|
|
- name: Set MariaDB Cron to /etc/cron.d
|
|
template:
|
|
src: check-memory.cron
|
|
dest: /etc/cron.d/vn-check-memory
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=r,o=r
|
|
|
|
- name: Configure MariaDB scheduler log CRON
|
|
copy:
|
|
src: scheduler-log.cron
|
|
dest: /etc/cron.d/vn-scheduler-log
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=r,o=r
|
|
|
|
- name: Insert MySQL certificates
|
|
no_log: true
|
|
copy:
|
|
content: "{{ item.content }}"
|
|
dest: "{{ item.dest }}"
|
|
owner: mysql
|
|
group: mysql
|
|
mode: "{{ item.mode }}"
|
|
loop: "{{ certificates }}"
|
|
notify: restart-mariadb
|
|
|
|
- name: Ensure required directories exist
|
|
file:
|
|
path: "{{ item.path }}"
|
|
state: directory
|
|
owner: "{{ item.owner }}"
|
|
group: "{{ item.group }}"
|
|
mode: "{{ item.mode }}"
|
|
loop: "{{ required_directories }}"
|
|
|
|
- when: db.branch == 'master'
|
|
block:
|
|
|
|
- name: Ensure required directories exist in Production
|
|
file:
|
|
path: "{{ item.path }}"
|
|
state: directory
|
|
owner: "{{ item.owner }}"
|
|
group: "{{ item.group }}"
|
|
mode: "{{ item.mode }}"
|
|
loop: "{{ required_directories_master }}"
|
|
|
|
- name: Set MariaDB custom configuration Production
|
|
copy:
|
|
src: "{{ item }}"
|
|
dest: /etc/mysql/mariadb.conf.d/
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=r,o=r
|
|
with_items:
|
|
- "mariaconfigfiles/z90-vn.cnf"
|
|
- "mariaconfigfiles/z95-production.cnf"
|
|
notify: restart-mariadb
|
|
|
|
- name: Reminder to check mount points
|
|
debug:
|
|
msg: |
|
|
Remember to check the following mount points:
|
|
- /var/lib/mysql
|
|
- /mnt/mysqlbin
|
|
- /mnt/local-backup
|
|
Make sure they are correctly configured and accessible.
|
|
|
|
- when: db.branch == 'test'
|
|
|
|
block:
|
|
- name: Set MariaBackup custom template configuration TestDB
|
|
template:
|
|
src: test-db_dev/apply.config.sh
|
|
dest: /root/mariabackup/
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=,o=
|
|
|
|
- name: Reminder to check mount points environment TestDB
|
|
debug:
|
|
msg: |
|
|
Remember to check the following mount points:
|
|
- /mnt/mysqltmp
|
|
Make sure they are correctly configured and accessible.
|
|
|
|
- when: db.branch == 'dev'
|
|
|
|
block:
|
|
- name: Set MariaBackup custom template configuration DevDB
|
|
template:
|
|
src: test-db_dev/apply.config.sh
|
|
dest: /root/mariabackup/
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=,o=
|
|
|
|
- name: Reminder to check mount points environment DevDB
|
|
debug:
|
|
msg: |
|
|
Remember to check the following mount points:
|
|
- /mnt/mysqltmp
|
|
Make sure they are correctly configured and accessible.
|
|
|
|
- when: db.branch == 'dev' or db.branch == 'test'
|
|
|
|
block:
|
|
- name: Set MariaDB custom configuration TestDB or DevDB
|
|
copy:
|
|
src: "{{ item }}"
|
|
dest: /etc/mysql/mariadb.conf.d/
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=r,o=r
|
|
with_items:
|
|
- "files/mariaconfigfiles/z90-vn.cnf"
|
|
- "files/mariaconfigfiles/z92-testing_dev.cnf"
|
|
notify: restart-mariadb
|
|
|
|
- name: Set Mariabackup files for TestDB or DevDB
|
|
copy:
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
owner: root
|
|
group: root
|
|
mode: "{{ item.mode }}"
|
|
loop: "{{ mariabackup_test_dev_files }}"
|
|
|
|
- name: Set Custom Configuration local template all Environment
|
|
template:
|
|
src: z99-local.cnf
|
|
dest: /etc/mysql/mariadb.conf.d/
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=r,o=r
|
|
|
|
- name: Set MariaBackup custom template configuration all Environment
|
|
template:
|
|
src: "my.cnf"
|
|
dest: /root/mariabackup/
|
|
owner: root
|
|
group: root
|
|
mode: u=rw,g=,o=
|
|
|
|
- name: Check if /var/lib/mysql/ exists
|
|
stat:
|
|
path: /var/lib/mysql/
|
|
register: mysql_dir
|
|
|
|
- when: mysql_dir.stat.exists
|
|
block:
|
|
|
|
- name: Sync MySQL data directory
|
|
synchronize:
|
|
src: /var/lib/mysql/
|
|
dest: /mnt/mysqldata/mysql/
|
|
archive: true
|
|
compress: true
|
|
recursive: true
|
|
delegate_to: "{{ inventory_hostname }}"
|
|
|
|
- name: Remove old MySQL data after sync
|
|
file:
|
|
path: /var/lib/mysql/
|
|
state: absent
|
|
|
|
- name: Ensure required custom and Mariabackup files are copied to their destinations and root scripts
|
|
copy:
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
owner: root
|
|
group: root
|
|
mode: "{{ item.mode }}"
|
|
loop: "{{ required_files_and_mariabackup_files_and_root_scripts }}"
|
|
notify: reload-systemd
|
|
|
|
- name: Mount all filesystems from /etc/fstab
|
|
command: mount -a
|
|
when: fstab.changed |