summaryrefslogtreecommitdiff
path: root/test/integration/targets/setup_mariadb/tasks/setup_mariadb.yml
blob: 7c3a1c3483b0b61e6a97803d10474d2d7afa5d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# We run two servers listening different ports
# to be able to check replication (one server for primary, another for replica).

- name: Include distribution specific variables
  include_vars: "{{ lookup('first_found', params) }}"
  vars:
    params:
      files:
        - "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml"
        - "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
        - "{{ ansible_facts.distribution }}.yml"
        - "{{ ansible_facts.os_family }}.yml"
        - default.yml
      paths:
        - vars

- name: Install MariaDB repo
  yum_repository:
    name: MariaDB
    description: MariaDB official repo
    baseurl: "{{ repo_link }}"
    gpgkey: "{{ repo_gpgkey }}"
    gpgcheck: yes
  notify: cleanup mariadb

- name: Install MariaDB packages
  yum:
    name: "{{ mariadb_packages }}"
    enablerepo: "{{ mariadb_enable_repo | default(omit) }}"
  notify: cleanup mariadb

- name: Create directories for instances
  file:
    state: directory
    path: "{{ item }}"
    owner: mysql
    group: mysql
  loop:
    - "{{ primary_db.datadir }}"
    - "{{ primary_db.logdir }}"
    - "{{ replica_db.datadir }}"
    - "{{ replica_db.logdir }}"
  notify: cleanup mariadb

- name: Copy configuration templates
  template:
    src: "{{ 'my' ~ item ~ '.j2' }}"
    dest: /etc/my.cnf.d/my{{ item }}.cnf
    owner: mysql
    group: mysql
    force: yes
  when: ansible_facts.distribution_major_version is version('7', '==')
  loop:
    - '{{ primary_db.name }}'
    - '{{ replica_db.name }}'

- name: Copy configuration template
  template:
    src: my.cnf.j2
    dest: /etc/my.cnf
    owner: mysql
    group: mysql
    force: yes
  when: ansible_facts.distribution_major_version is version('8', '==')

- name: Initialize DBs
  shell: 'mysql_install_db --user=mysql --datadir={{ item }}'
  loop:
  - '{{ primary_db.datadir }}'
  - '{{ replica_db.datadir }}'

- name: Start services
  service:
    name: mariadb@{{ item }}
    state: started
  loop:
    - "{{ primary_db.name }}"
    - "{{ replica_db.name }}"

- pause:
    seconds: 3

########### For painful debug uncomment the lines below ##
#- name: DEBUG Check stratup log
#  shell: cat /var/log/mariadb/mariadb.log

#- name: DEBUG Check mysql_safe err log
#  shell: cat '{{  mysql_safe_err_log }}'

#- name: DEBUG Check processes
#  shell: 'ps aux | grep mysqld | grep -v "grep\|root"'

#- name: DEBUG
#  yum: name=net-tools

#- name: DEBUG
#  shell: "netstat -ntpl"

#- name: DEBUG
#  shell: cat /etc/my.cnf
##########################################################

- name: Check connection to the primary
  shell: 'echo "SHOW DATABASES;" | mysql -P {{ primary_db.port }} -h 127.0.0.1'

- name: Check connection to the replica
  shell: "echo \"SHOW VARIABLES LIKE 'datadir';\" | mysql -P {{ replica_db.port }} -h 127.0.0.1"