main.yml 1.4 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
Lars Beckers's avatar
Lars Beckers committed
40
    # yamllint disable-line rule:line-length
41
    password: "{{ lookup('passwordstore', 'db/{{ ansible_hostname }}-mysql create=true length=20') }}"
42
    login_user: root
Lars Beckers's avatar
Lars Beckers committed
43
    # yamllint disable-line rule:line-length
44
    login_password: "{{ lookup('passwordstore', 'db/{{ ansible_hostname }}-mysql create=true length=20') }}"
45
  register: mysql_root_creation_result
Lars Beckers's avatar
Lars Beckers committed
46
47
  no_log: true
  ignore_errors: true
48
49
50
51
52
53
54
  tags:
    - mysql
    - config

- name: initialize the mysql root user
  mysql_user:
    name: root
Lars Beckers's avatar
Lars Beckers committed
55
    # yamllint disable-line rule:line-length
56
    password: "{{ lookup('passwordstore', 'db/{{ ansible_hostname }}-mysql create=true length=20') }}"
Lars Beckers's avatar
Lars Beckers committed
57
  no_log: true
58
59
60
61
  when: mysql_root_creation_result|failed
  tags:
    - mysql
    - config