main.yml 1.48 KB
Newer Older
1
2
3
---
# file: roles/mysql/tasks/main.yml

4
- name: ensure mysql packages are installed
Robin Sonnabend's avatar
Robin Sonnabend committed
5
6
7
  apt:
    name:
      - mariadb-server
8
      - python3-mysqldb
Robin Sonnabend's avatar
Robin Sonnabend committed
9
    state: present
10
11
12
13
  tags:
    - packages
    - mysql

14
15
16
17
18
19
20
- name: ensure legacy mysql packages are installed
  apt:
    name:
      - python-mysqldb
    state: present
  when: ansible_distribution_major_version|int(default=99) < 11

21
- name: ensure mysql is started
Lars Beckers's avatar
Lars Beckers committed
22
23
24
25
  service:
    name: mysql
    state: started
    enabled: true
26

27
28
29
30
31
32
33
34
35
- name: setup mysql backups with rsnapshot
  when: '{{mysql_rsnapshot}}'
  block:
    - name: ensure a read-only mysql user for backups exists
      mysql_user:
        name: "{{ mysql_backup_user }}"
        password: "{{ mysql_backup_password }}"
        priv: "*.*:SELECT,LOCK TABLES"
      no_log: true
36

37
38
39
40
41
42
43
    - name: ensure the backup procedure can access the backup password
      template:
        src: my.cnf
        dest: "/root/.mysql-{{ mysql_backup_user }}.cnf"
        owner: root
        group: root
        mode: '0600'
44

45
46
47
48
49
50
51
    - name: deploy the mysql backup script
      template:
        src: mysqlbackup.sh
        dest: /usr/local/bin/
        owner: root
        group: root
        mode: '0755'
52

53
54
55
56
57
58
59
    - name: ensure we backup all the mysql databases with rsnapshot
      copy:
        src: rsnapshot.conf
        dest: /etc/rsnapshot.d/mysql.conf
        owner: root
        group: root
        mode: '0644'
60

61
62
63
64
    - name: remove obsolete crontab
      file:
        path: /etc/cron.d/mysql-snapshot
        state: absent