mirror of
https://github.com/aljazceru/ansible-role-mysql.git
synced 2025-12-19 11:24:19 +01:00
Stylistic cleanup and reorganization.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
---
|
||||
- name: restart mysql
|
||||
service: >
|
||||
name={{ mysql_daemon }}
|
||||
state=restarted
|
||||
service: "name={{ mysql_daemon }} state=restarted"
|
||||
|
||||
@@ -11,6 +11,7 @@ galaxy_info:
|
||||
- name: EL
|
||||
versions:
|
||||
- 6
|
||||
- 7
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- all
|
||||
|
||||
12
tasks/configure.yml
Normal file
12
tasks/configure.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: Copy my.cnf global MySQL configuration.
|
||||
template:
|
||||
src: my.cnf.j2
|
||||
dest: /etc/my.cnf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify: restart mysql
|
||||
|
||||
- name: Ensure MySQL is started and enabled on boot.
|
||||
service: "name={{ mysql_daemon }} state=started enabled=yes"
|
||||
17
tasks/databases-users.yml
Normal file
17
tasks/databases-users.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- name: Ensure MySQL databases are present.
|
||||
mysql_db:
|
||||
name: "{{ item.name }}"
|
||||
collation: "{{ item.collation | default('utf8_general_ci') }}"
|
||||
encoding: "{{ item.encoding | default('utf8') }}"
|
||||
state: present
|
||||
with_items: mysql_databases
|
||||
|
||||
- name: Ensure MySQL users are present.
|
||||
mysql_user:
|
||||
name: "{{ item.name }}"
|
||||
host: "{{ item.host | default('localhost') }}"
|
||||
password: "{{ item.password }}"
|
||||
priv: "{{ item.priv | default('*.*:USAGE') }}"
|
||||
state: present
|
||||
with_items: mysql_users
|
||||
@@ -2,79 +2,12 @@
|
||||
- name: Include OS-specific variables.
|
||||
include_vars: "{{ ansible_os_family }}.yml"
|
||||
|
||||
- name: Update postfix to the latest version (if extra repositories enabled).
|
||||
yum: >
|
||||
name=postfix
|
||||
state=latest
|
||||
enablerepo={{ mysql_enablerepo }}
|
||||
when: mysql_enablerepo != ""
|
||||
|
||||
- include: setup-RedHat.yml
|
||||
when: ansible_os_family == 'RedHat'
|
||||
|
||||
- include: setup-Debian.yml
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Copy my.cnf global MySQL configuration.
|
||||
template: >
|
||||
src=my.cnf.j2
|
||||
dest=/etc/my.cnf
|
||||
owner=root group=root mode=644
|
||||
notify: restart mysql
|
||||
|
||||
- name: Ensure MySQL is started and enabled on boot.
|
||||
service: >
|
||||
name={{ mysql_daemon }}
|
||||
state=started
|
||||
enabled=yes
|
||||
|
||||
- name: Check if .my.cnf file already exists.
|
||||
stat: "path={{ mysql_user_home }}/.my.cnf"
|
||||
register: mycnf_file
|
||||
|
||||
# 'localhost' needs to be the last item for idempotency, see
|
||||
# http://ansible.cc/docs/modules.html#mysql-user
|
||||
- name: Update MySQL root password for all root accounts.
|
||||
mysql_user: >
|
||||
name=root
|
||||
host={{ item }}
|
||||
password={{ mysql_root_password }}
|
||||
with_items:
|
||||
- 127.0.0.1
|
||||
- ::1
|
||||
- localhost
|
||||
when: mycnf_file.stat.exists == false
|
||||
|
||||
# Has to be after the root password assignment, for idempotency.
|
||||
- name: Copy .my.cnf file with root password credentials.
|
||||
template: >
|
||||
src=python-my.cnf.j2
|
||||
dest={{ mysql_user_home }}/.my.cnf
|
||||
owner=root group=root mode=600
|
||||
|
||||
- name: Delete anonymous MySQL user for localhost.
|
||||
mysql_user: >
|
||||
name=""
|
||||
state=absent
|
||||
|
||||
- name: Remove the MySQL test database.
|
||||
mysql_db: >
|
||||
name="test"
|
||||
state=absent
|
||||
|
||||
- name: Ensure MySQL databases are present.
|
||||
mysql_db: >
|
||||
name="{{ item.name }}"
|
||||
collation="{{ item.collation | default('utf8_general_ci') }}"
|
||||
encoding="{{ item.encoding | default('utf8') }}"
|
||||
state=present
|
||||
with_items: mysql_databases
|
||||
|
||||
- name: Ensure MySQL users are present.
|
||||
mysql_user: >
|
||||
name="{{ item.name }}"
|
||||
host="{{ item.host | default('localhost') }}"
|
||||
password="{{ item.password }}"
|
||||
priv="{{ item.priv | default('*.*:USAGE') }}"
|
||||
state=present
|
||||
with_items: mysql_users
|
||||
- include: configure.yml
|
||||
- include: secure-installation.yml
|
||||
- include: databases-users.yml
|
||||
|
||||
32
tasks/secure-installation.yml
Normal file
32
tasks/secure-installation.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
- name: Check if .my.cnf file already exists.
|
||||
stat: "path={{ mysql_user_home }}/.my.cnf"
|
||||
register: mycnf_file
|
||||
|
||||
# 'localhost' needs to be the last item for idempotency, see
|
||||
# http://ansible.cc/docs/modules.html#mysql-user
|
||||
- name: Update MySQL root password for all root accounts.
|
||||
mysql_user:
|
||||
name: "root"
|
||||
host: "{{ item }}"
|
||||
password: "{{ mysql_root_password }}"
|
||||
with_items:
|
||||
- 127.0.0.1
|
||||
- ::1
|
||||
- localhost
|
||||
when: mycnf_file.stat.exists == false
|
||||
|
||||
# Has to be after the root password assignment, for idempotency.
|
||||
- name: Copy .my.cnf file with root password credentials.
|
||||
template:
|
||||
src: "python-my.cnf.j2"
|
||||
dest: "{{ mysql_user_home }}/.my.cnf"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
|
||||
- name: Remove anonymous MySQL user.
|
||||
mysql_user: "name='' state=absent"
|
||||
|
||||
- name: Remove MySQL test database.
|
||||
mysql_db: "name='test' state=absent"
|
||||
@@ -8,7 +8,5 @@
|
||||
when: mysql_installed.stat.exists == false
|
||||
|
||||
- name: Ensure MySQL packages are installed.
|
||||
apt: >
|
||||
name={{ item }}
|
||||
state=installed
|
||||
apt: "name={{ item }} state=installed"
|
||||
with_items: mysql_packages
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
- name: Update postfix to the latest version (if extra repositories enabled).
|
||||
yum: "name=postfix state=latest enablerepo={{ mysql_enablerepo }}"
|
||||
when: mysql_enablerepo != ""
|
||||
|
||||
- name: Ensure MySQL packages are installed.
|
||||
yum: >
|
||||
name={{ item }}
|
||||
state=installed
|
||||
enablerepo={{ mysql_enablerepo }}
|
||||
yum: "name={{ item }} state=installed enablerepo={{ mysql_enablerepo }}"
|
||||
with_items: mysql_packages
|
||||
|
||||
Reference in New Issue
Block a user