106 lines
2.4 KiB
YAML
106 lines
2.4 KiB
YAML
- name: Install software-properties-common for add-apt-repository
|
|
apt:
|
|
pkg: software-properties-common
|
|
state: latest
|
|
|
|
- name: Ensure MariaDB 0xcbcb082a1bb943db signing key is installed
|
|
apt_key:
|
|
keyserver: "keyserver.ubuntu.com"
|
|
id: "0xcbcb082a1bb943db"
|
|
|
|
- name: Ensure MariaDB 0xF1656F24C74CD1D8 signing key is installed
|
|
apt_key:
|
|
keyserver: "keyserver.ubuntu.com"
|
|
id: "0xF1656F24C74CD1D8"
|
|
|
|
- name: Ensure MariaDB repository is present
|
|
apt_repository:
|
|
repo: "{{ item }}"
|
|
state: present
|
|
with_items:
|
|
- "deb [arch=amd64] http://ams2.mirrors.digitalocean.com/mariadb/repo/{{ mysql_version }}/debian {{ ansible_distribution_release }} main"
|
|
register: repoadded
|
|
|
|
- name: Updating the cache due to the addition of MariaDB repository
|
|
apt:
|
|
update_cache: yes
|
|
when: repoadded.changed
|
|
|
|
- name: Install MariaDB server/client
|
|
apt:
|
|
pkg: "{{ packages }}"
|
|
state: latest
|
|
vars:
|
|
packages:
|
|
- mariadb-server
|
|
- mariadb-client
|
|
- libmysqlclient18
|
|
- python-mysqldb
|
|
|
|
- name: Start MariaDB
|
|
service:
|
|
name: mariadb
|
|
state: started
|
|
|
|
- include_tasks: config.yml
|
|
|
|
- name: update MariaDB root password for all root accounts
|
|
mysql_user: name=root host={{ item }} password={{ mysql_root_db_pass }}
|
|
with_items:
|
|
- "{{ ansible_hostname }}"
|
|
- 127.0.0.1
|
|
- ::1
|
|
- localhost
|
|
when: ansible_hostname != 'localhost'
|
|
|
|
- name: update MariaDB root password for all root accounts
|
|
mysql_user:
|
|
name: root
|
|
host: "{{ item }}"
|
|
password: "{{ mysql_root_db_pass }}"
|
|
with_items:
|
|
- 127.0.0.1
|
|
- ::1
|
|
- localhost
|
|
when: ansible_hostname == 'localhost'
|
|
|
|
- name: copy .my.cnf file with root password credentials
|
|
template:
|
|
src: .my.cnf.j2
|
|
dest: ~/.my.cnf
|
|
mode: 0600
|
|
|
|
- name: ensure anonymous users are not in the database
|
|
mysql_user:
|
|
name: ''
|
|
host: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- localhost
|
|
- "{{ ansible_hostname }}"
|
|
|
|
- name: remove the test database
|
|
mysql_db: name=test state=absent
|
|
become: true
|
|
|
|
- name: Add MySQL databases
|
|
mysql_db:
|
|
name: '{{ item.name }}'
|
|
state: '{{ item.state }}'
|
|
with_items:
|
|
- "{{ mysql_databases }}"
|
|
|
|
- name: Remove wildcard host users
|
|
include_tasks: remove_wildcard.yml
|
|
with_items:
|
|
- "{{ mysql_users }}"
|
|
loop_control:
|
|
loop_var: mysql_user
|
|
|
|
- name: Add users to MariaDB
|
|
include_tasks: user.yml
|
|
with_items:
|
|
- "{{ mysql_users }}"
|
|
loop_control:
|
|
loop_var: mysql_user
|