ansible-roles/mysql/tasks/utils.yml
Mathieu Trossevin 2036db938b
[Cleanup] Cleanup the mysql role
Remove the useless call for `cat` as `grep` take a file as it's second
argument that tell it to search for the pattern in a specific file
instead of whatever is passed to it through stdin.

Name both task defining the position of the config directory for
self-documentation purposes (and please ansible-lint defaults).

Change role description to it's description in the readme instead of the
default description asking for the role to be described.

Don't compare to empty string, an empty string is already false while a
non-empty string is true.
2020-12-23 15:02:20 +01:00

190 lines
4.1 KiB
YAML

---
- include_role:
name: evolix/remount-usr
when: (mysql_scripts_dir or general_scripts_dir) is search ("/usr")
- name: Ensure scripts directory exists
file:
dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}"
mode: "0700"
state: directory
tags:
- mysql
# mytop
- name: "Install mytop (jessie)"
apt:
name: mytop
state: present
tags:
- packages
- mytop
- mysql
when: ansible_distribution_release == "jessie"
- name: "Install dependencies for mytop (stretch)"
apt:
name:
- mariadb-client-10.1
- libconfig-inifiles-perl
- libterm-readkey-perl
when: ansible_distribution_release == "stretch"
- name: "Install dependencies for mytop (Debian 10 or later)"
apt:
name:
- mariadb-client-10.3
- libconfig-inifiles-perl
- libterm-readkey-perl
when: ansible_distribution_major_version is version('10', '>=')
- name: Read debian-sys-maint password
shell: 'grep -m1 "password = .*" /etc/mysql/debian.cnf | cut -d" " -f3'
register: mysql_debian_password
changed_when: False
check_mode: no
tags:
- mysql
- name: Configure mytop
template:
src: mytop.j2
dest: /root/.mytop
mode: "0600"
force: yes
tags:
- mytop
- mysql
# mysqltuner
- include_role:
name: evolix/remount-usr
when: (mysql_scripts_dir or general_scripts_dir) is search ("/usr")
- name: Install mysqltuner
# copy:
# src: mysqltuner.pl
# dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}/mysqltuner.pl"
# mode: "0700"
apt:
name: mysqltuner
state: present
tags:
- mysql
- mysqltuner
- name: Install aha
apt:
name: aha
tags:
- mysql
# Percona Toolkit
- name: "Install percona-toolkit (Debian 9 or later)"
apt:
name: percona-toolkit
state: present
tags:
- packages
- percona-toolkit
- mysql
when: ansible_distribution_major_version is version('9', '>=')
# automatic optimizations
- include_role:
name: evolix/remount-usr
when: (mysql_scripts_dir or general_scripts_dir) is search ("/usr")
- name: Optimize script for MySQL
copy:
src: mysql-optimize.sh
dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}/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
- name: "Enable cron to optimize MySQL"
file:
src: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}/mysql-optimize.sh"
dest: /etc/cron.{{ mysql_cron_optimize_frequency | mandatory }}/mysql-optimize.sh
state: link
when: mysql_cron_optimize
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
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
- 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
tags:
- mysql
- name: "Disable mysqltuner in cron"
file:
dest: /etc/cron.{{ mysql_cron_mysqltuner_frequency | mandatory }}/mysqltuner.sh
state: absent
when: not mysql_cron_mysqltuner
tags:
- mysql
# my-add.sh
- include_role:
name: evolix/remount-usr
when: (mysql_scripts_dir or general_scripts_dir) is search ("/usr")
- name: Install my-add.sh
copy:
src: my-add.sh
dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}/my-add.sh"
mode: "0700"
tags:
- mysql
- name: Install apg
apt:
name: apg
tags:
- mysql
- packages
- name: "Install save_mysql_processlist.sh"
copy:
src: save_mysql_processlist.sh
dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}/save_mysql_processlist.sh"
mode: "0755"
force: no
tags:
- mysql