ansible-roles/mysql-oracle/tasks/utils.yml

215 lines
4.4 KiB
YAML

---
- set_fact:
_mysql_scripts_dir: "{{ mysql_scripts_dir | default(general_scripts_dir, True) | mandatory }}"
- include_role:
name: evolix/remount-usr
when: _mysql_scripts_dir is search("/usr")
- name: Scripts directory exists
file:
dest: "{{ _mysql_scripts_dir }}"
mode: "0700"
state: directory
tags:
- mysql
# mytop
- name: "mytop is installed (Debian 9)"
apt:
name: mytop
state: present
tags:
- packages
- mytop
- mysql
when: ansible_distribution_release == "jessie"
# - name: "mysql-utilities are installed (Debian 9 or later)"
# apt:
# name: mysql-utilities
# when: ansible_distribution_major_version is version('9', '>=')
- name: "mytop dependencies are installed (Buster)"
apt:
name:
- libconfig-inifiles-perl
- libdbd-mysql-perl
- libdbi-perl
- libterm-readkey-perl
- libtime-hires-perl
tags:
- packages
- mytop
- mysql
when: ansible_distribution_release == "stretch"
- name: "Install dependencies for mytop (Debian 10)"
apt:
name:
- mariadb-client-10.3
- libconfig-inifiles-perl
- libterm-readkey-perl
when: ansible_distribution_release == "buster"
- name: "Install dependencies for mytop (Debian 11 or later)"
apt:
name:
- mariadb-client-10.5
- libconfig-inifiles-perl
- libterm-readkey-perl
when: ansible_distribution_major_version is version('11', '>=')
- include_role:
name: evolix/remount-usr
tags:
- mytop
- mysql
- name: "mytop is installed (Debian 9 or later)"
copy:
src: mytop
dest: /usr/local/bin/mytop
mode: "0755"
owner: root
group: staff
force: yes
tags:
- mytop
- mysql
when: ansible_distribution_major_version is version('9', '>=')
- name: Read debian-sys-maint password
shell: 'cat /etc/mysql/debian.cnf | grep -m1 "password = .*" | cut -d" " -f3'
register: mysql_debian_password
changed_when: False
check_mode: no
tags:
- mytop
- mysql
- name: mytop configuration is copied
template:
src: mytop-config.j2
dest: /root/.mytop
mode: "0600"
force: yes
tags:
- mytop
- mysql
# mysqltuner
- include_role:
name: evolix/remount-usr
tags:
- mysql
when: _mysql_scripts_dir is search("/usr")
- name: mysqltuner is installed
# copy:
# src: mysqltuner.pl
# dest: "{{ _mysql_scripts_dir }}/mysqltuner.pl"
# mode: "0700"
apt:
name: mysqltuner
state: present
tags:
- mysql
- mysqltuner
- name: aha is installed
apt:
name: aha
tags:
- mysql
# automatic optimizations
- include_role:
name: evolix/remount-usr
tags:
- mysql
when: _mysql_scripts_dir is search("/usr")
- name: mysql-optimize.sh is installed
copy:
src: mysql-optimize.sh
dest: "{{ _mysql_scripts_dir }}/mysql-optimize.sh"
mode: "0700"
tags:
- mysql
- name: "Cron dir for optimize is present"
file:
path: "/etc/cron.{{ mysql_cron_optimize_frequency | mandatory }}"
state: directory
mode: "0755"
owner: root
group: root
tags:
- mysql
- name: "Enable cron to optimize MySQL"
file:
src: "{{ _mysql_scripts_dir }}/mysql-optimize.sh"
dest: /etc/cron.{{ mysql_cron_optimize_frequency | mandatory }}/mysql-optimize.sh
state: link
when: mysql_cron_optimize | bool
tags:
- mysql
- name: "Disable cron to optimize MySQL"
file:
dest: /etc/cron.{{ mysql_cron_optimize_frequency | mandatory }}/mysql-optimize.sh
state: absent
when: not (mysql_cron_optimize | bool)
tags:
- mysql
- name: "Cron dir for mysqltuner is present"
file:
path: "/etc/cron.{{ mysql_cron_mysqltuner_frequency | mandatory }}"
state: directory
mode: "0755"
owner: root
group: root
tags:
- mysql
- mysqltuner
- name: "Enable mysqltuner in cron"
copy:
src: mysqltuner.cron.sh
dest: /etc/cron.{{ mysql_cron_mysqltuner_frequency | mandatory }}/mysqltuner.sh
mode: "0755"
when: mysql_cron_mysqltuner | bool
tags:
- mysql
- mysqltuner
- name: "Disable mysqltuner in cron"
file:
dest: /etc/cron.{{ mysql_cron_mysqltuner_frequency | mandatory }}/mysqltuner.sh
state: absent
when: not (mysql_cron_mysqltuner | bool)
tags:
- mysql
- mysqltuner
# my-add.sh
- include_role:
name: evolix/remount-usr
when: _mysql_scripts_dir is search("/usr")
- name: Install my-add.sh
copy:
src: my-add.sh
dest: "{{ _mysql_scripts_dir }}/my-add.sh"
mode: "0700"
tags:
- mysql