mirror of
https://github.com/geerlingguy/ansible-role-apache
synced 2025-01-10 11:50:18 +01:00
3a15b07608
Inspired by the Ansibles.mysql role.
89 lines
2.3 KiB
YAML
89 lines
2.3 KiB
YAML
---
|
|
- 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 != ""
|
|
|
|
- name: Ensure MySQL packages are installed (RedHat).
|
|
yum: >
|
|
name={{ item }}
|
|
state=installed
|
|
enablerepo={{ mysql_enablerepo }}
|
|
with_items: mysql_packages
|
|
when: ansible_os_family == 'RedHat'
|
|
|
|
- name: Ensure MySQL packages are installed (Debian).
|
|
apt: >
|
|
name={{ item }}
|
|
state=installed
|
|
with_items: mysql_packages
|
|
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
|