Add support for Debian/Ubuntu.

pull/63/head
Jeff Geerling 10 years ago
parent 9fc1bbd1ea
commit a7998b3b9a
  1. 12
      README.md
  2. 4
      handlers/main.yml
  3. 6
      meta/main.yml
  4. 56
      tasks/main.yml
  5. 5
      vars/Debian.yml
  6. 6
      vars/RedHat.yml
  7. 11
      vars/main.yml

@ -1,6 +1,6 @@
# Ansible Role: MySQL
Installs MySQL server on RedHat Enterprise Linux or CentOS 6.x servers.
Installs MySQL server on RHEL/CentOS or Debian/Ubuntu servers.
## Requirements
@ -10,9 +10,9 @@ None.
Available variables are listed below, along with default values (see `vars/main.yml`):
mysql_enablerepo: ""
mysql_user_home: /root
If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. `remi,epel`). This can be handy, as an example, if you want to install later versions of MySQL.
The home directory inside which Python MySQL settings will be stored, which Ansible will use when connecting to MySQL. This should be the home directory of the user which runs this Ansible role.
mysql_root_password: root
@ -23,7 +23,11 @@ The MySQL root user account password.
- mysql-server
- MySQL-python
Packages to be installed. In some situations, you may need to add additional packages, like `mysql-devel`.
(OS-specific, RedHat/CentOS defaults listed here) Packages to be installed. In some situations, you may need to add additional packages, like `mysql-devel`.
mysql_enablerepo: ""
(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. `remi,epel`). This can be handy, as an example, if you want to install later versions of MySQL.
## Dependencies

@ -1,3 +1,5 @@
---
- name: restart mysql
command: service mysqld restart
service: >
name={{ mysql_daemon }}
state=restarted

@ -11,5 +11,11 @@ galaxy_info:
- name: EL
versions:
- 6
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
categories:
- database

@ -1,24 +1,45 @@
---
# If this is not done for the version of MySQL in certain extra repositories,
# MySQL installation fails with an error the first time.
- name: Update postfix to the latest version.
yum: name=postfix state=latest enablerepo={{ mysql_enablerepo }}
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
- name: Ensure MySQL packages are installed.
yum: name={{ item }} state=installed enablerepo={{ mysql_enablerepo }}
- 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.
copy: src=my.cnf dest=/etc/my.cnf owner=root group=root mode=0644
# Set MySQL to run at startup.
- name: Ensure MySQL is started.
service: name=mysqld state=started enabled=yes
- name: Ensure MySQL is started and enabled on boot.
service: >
name={{ mysql_daemon }}
state=started
enabled=yes
# '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 }}
- 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
@ -26,10 +47,17 @@
# Has to be after the root password assignment, for idempotency.
- name: Copy .my.cnf file with root password credentials.
template: src=my.cnf.j2 dest=/root/.my.cnf owner=root group=root mode=0600
template: >
src=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"
mysql_user: >
name=""
state=absent
- name: Remove the MySQL test database.
mysql_db: name="test" state="absent"
mysql_db: >
name="test"
state=absent

@ -0,0 +1,5 @@
---
mysql_daemon: mysql
mysql_packages:
- mysql-server
- python-mysqldb

@ -0,0 +1,6 @@
---
mysql_daemon: mysqld
mysql_packages:
- mysql
- mysql-server
- MySQL-python

@ -1,8 +1,7 @@
---
# Pass in a comma-separated list of repos to use (e.g. "remi,epel").
mysql_enablerepo: ""
mysql_user_home: /root
mysql_root_password: root
mysql_packages:
- mysql
- mysql-server
- MySQL-python
# Pass in a comma-separated list of repos to use (e.g. "remi,epel"). Used only
# for RedHat systems (and derivatives).
mysql_enablerepo: ""