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

4
- name: ensure mysql packages are installed for jessie
Robin Sonnabend's avatar
Robin Sonnabend committed
5
6
7
8
9
  apt:
    name:
      - mysql-server
      - python-mysqldb
    state: present
10
11
12
13
14
15
16
  when:
    - debian_version == "jessie"
  tags:
    - packages
    - mysql

- name: ensure mysql packages are installed for stretch
Robin Sonnabend's avatar
Robin Sonnabend committed
17
18
19
20
21
  apt:
    name:
      - mariadb-server
      - python-mysqldb
    state: present
22
  when:
Robin Sonnabend's avatar
Robin Sonnabend committed
23
    - debian_version != "jessie"
24
25
26
27
28
  tags:
    - packages
    - mysql

- name: ensure mysql is started
Lars Beckers's avatar
Lars Beckers committed
29
30
31
32
  service:
    name: mysql
    state: started
    enabled: true
33
34
35
  tags:
    - service
    - mysql
36
37
38
39

- name: ensure the mysql root user exists and has the correct password
  mysql_user:
    name: root
40
    password: "{{ mysql_root_password }}"
41
    login_user: root
42
    login_password: "{{ mysql_root_password }}"
43
  register: mysql_root_creation_result
Lars Beckers's avatar
Lars Beckers committed
44
45
  no_log: true
  ignore_errors: true
46
47
48
49
50
51
52
  tags:
    - mysql
    - config

- name: initialize the mysql root user
  mysql_user:
    name: root
53
    password: "{{ mysql_root_password }}"
Lars Beckers's avatar
Lars Beckers committed
54
  no_log: true
55
56
57
58
  when: mysql_root_creation_result|failed
  tags:
    - mysql
    - config