main.yml 1.6 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
8
9
  apt:
    name:
      - mariadb-server
      - python-mysqldb
    state: present
10
11
12
13
14
  tags:
    - packages
    - mysql

- name: ensure mysql is started
Lars Beckers's avatar
Lars Beckers committed
15
16
17
18
  service:
    name: mysql
    state: started
    enabled: true
19
20
21
22

- name: ensure the mysql root user exists and has the correct password
  mysql_user:
    name: root
23
    password: "{{ mysql_root_password }}"
24
    login_user: root
25
    login_password: "{{ mysql_root_password }}"
26
  register: mysql_root_creation_result
Lars Beckers's avatar
Lars Beckers committed
27
28
  no_log: true
  ignore_errors: true
29
30
31
32

- name: initialize the mysql root user
  mysql_user:
    name: root
33
    password: "{{ mysql_root_password }}"
Lars Beckers's avatar
Lars Beckers committed
34
  no_log: true
35
  when: mysql_root_creation_result is failed
36
37
38
39
40
41
42
43
44
45
46
47

- name: ensure a read-only mysql user for backups exists
  mysql_user:
    name: "{{ mysql_backup_user }}"
    password: "{{ mysql_backup_password }}"
    login_user: root
    login_password: "{{ mysql_root_password }}"
    priv: "*.*:SELECT,LOCK TABLES"

- name: ensure the backup procedure can access the backup password
  template:
    src: my.cnf
Thomas Schneider's avatar
Thomas Schneider committed
48
    dest: "/root/.mysql-{{ mysql_backup_user }}.cnf"
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    owner: root
    group: root
    mode: '0600'

- name: deploy the mysql backup script
  template:
    src: mysqlbackup.sh
    dest: /usr/local/bin/
    owner: root
    group: root
    mode: '0755'

- 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'

69
70
71
72
- name: remove obsolete crontab
  file:
    path: /etc/cron.d/mysql-snapshot
    state: absent