Import tasks/defaults/templates/readme from old repo

pull/6/head
Emilien Mantel 2015-07-12 11:50:23 +02:00
parent 4955653d48
commit 4e7528300e
12 changed files with 199 additions and 27 deletions

65
README.md.old 100644
View File

@ -0,0 +1,65 @@
MySQL role
==========
Actions
-------
- Install minimal packages
- Install [MariaDB](https://mariadb.org) or [MySQL](http://www.mysql.com) or [Percona Server](http://www.percona.com/software/percona-server)
- Configuration
- Secure your service
- Create databases
- Create users
Variables
---------
- mysql\_vendor: 'mariadb' or 'mysql' or 'percona' (mariadb is default)
- mysql\_root\_password: default password used when installing database service
### Configuration
- mysql\_cnf: key/value hash see [defaults/main.yml](default vars file)
### Databases
- mysql\_databases: list
### Users
Example:
```
mysql\_users:
- name: 'kiki'
password: '123'
priv: hihi.*:ALL
```
Check "priv" syntax in [http://docs.ansible.com/mysql_user_module.html](mysql_user module documentation)
### MariaDB
- mariadb\_version (5.5, 10.0, 10.1)
- mariadb\_repository (see: [http://mariadb.org/mariadb/repositories/](MariaDB repositories tool))
### Percona
- percona\_version (5.5, 5.6)
- percona\_repository (see: [http://www.percona.com/doc/percona-server/5.5/installation/apt_repo.html](Percona APT doc))
Notes
-----
- NEVER (yes NEVER), change your mysql\_vendor or versions! This role don't manage migrations/upgrades/downgrades.
- Be careful! If you use 'mysql' you can have 2 versions: 5.5 (from Debian repository) and 5.6 from [Dotdeb](https://www.dotdeb.org)
TODO
----
- Support Jessie
- Test "official" releases of MySQL [http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/](http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/)
- Manage Galera and other tools
- Manage replication
- You can secure your password with [http://docs.ansible.com/playbooks_vault.html](Ansible Vault)

View File

@ -4,7 +4,7 @@
# Setup
# -------------------------------------
mysql_origin: 'mariadb'
mysql_vendor: "mariadb"
mysql_vendor: 'mariadb'
mysql_root_password: 'change_me_NOW'
# -------------------------------------
@ -27,9 +27,9 @@ mysql_users: []
# -------------------------------------
# MariaDB
# -------------------------------------
mariadb_version: '10.1' # (5.5, 10.0, 10.1)
mariadb_version: '10.0' # (5.5, 10.0)
# See: http://mariadb.org/mariadb/repositories/
mariadb_repository: "http://ftp.igh.cnrs.fr/pub/mariadb/repo/{{ mariadb_version }}/debian"
mariadb_repository: 'http://ftp.igh.cnrs.fr/pub/mariadb/repo/{{ mariadb_version }}/debian'
# -------------------------------------
# Percona

View File

@ -0,0 +1,4 @@
---
- name: restart mysql
action: service name=mysql state=restarted enabled=yes

27
tasks/install.yml 100644
View File

@ -0,0 +1,27 @@
---
- name: INCLUDE | Install MySQL from default repo
include: 'install_default_mysql.yml'
when: mysql_origin == 'default' mysql_vendor == 'mysql'
- name: INCLUDE | Install MariaDB from Debian repo
include: 'install_default_mariadb.yml'
when: mysql_origin == 'default' and mysql_vendor == 'mariadb'
- name: INCLUDE | Install MariaDB from MariaDB repo
include: 'install_mariadb_mariadb.yml'
when: mysql_origin == 'mariadb' and mysql_vendor == 'mariadb'
- name: INCLUDE | Install Percona Server from Percona repo
include: 'install_percona_percona.yml'
when: mysql_origin == 'percona' and mysql_vendor == 'percona'
- name: APT | Install few MySQL related tools
apt: pkg={{ item }} state=latest
with_items:
- mytop
- percona-toolkit
- python-configparser
- python-mysqldb

View File

@ -0,0 +1,19 @@
---
- name: SHELL | Get MySQL target version
shell: LANG=C apt-cache depends mysql-server | awk -F '-' '/Depends/ { print $NF }'
register: mysql_version
when: not mysql_exists.stat.exists
changed_when: false
- name: SHELL | Prepare MySQL silent installation (root password)
shell: echo 'mysql-server-{{ mysql_version.stdout }} mysql-server/root_password password {{ mysql_root_password }}' | debconf-set-selections
when: not mysql_exists.stat.exists
- name: SHELL | Prepare MySQL silent installation (root password again)
shell: echo 'mysql-server-{{ mysql_version.stdout }} mysql-server/root_password_again password {{ mysql_root_password }}' | debconf-set-selections
when: not mysql_exists.stat.exists
- name: APT | Install MySQL server
apt: update_cache=yes cache_valid_time=3600 pkg=mysql-server state=latest

View File

@ -0,0 +1,22 @@
---
- name: SHELL | Prepare MariaDB silent installation (root password)
shell: echo 'mariadb-server-{{ mariadb_version }} mysql-server/root_password password {{ mysql_root_password }}' | debconf-set-selections
when: not mysql_exists.stat.exists
- name: SHELL | Prepare MariaDB silent installation (root password again)
shell: echo 'mariadb-server-{{ mariadb_version }} mysql-server/root_password_again password {{ mysql_root_password }}' | debconf-set-selections
when: not mysql_exists.stat.exists
- name: APT | Install MariaDB key
apt_key: keyserver="keyserver.ubuntu.com" id="0xcbcb082a1bb943db" state=present
- name: APT | Add MariaDB repository
apt_repository: repo='deb {{ mariadb_repository }} {{ ansible_distribution_release }} main' state=present
- name: APT | Add MariaDB (src) repository
apt_repository: repo='deb-src {{ mariadb_repository }} {{ ansible_distribution_release }} main' state=present
- name: APT | Install MariaDB
apt: update_cache=yes cache_valid_time=3600 pkg=mariadb-server state=latest

View File

@ -0,0 +1,28 @@
---
- name: APT_KEY | Install Percona key
#apt_key: keyserver="keys.gnupg.net" id="1C4CBDCDCD2EFD2A" state=present
apt_key: keyserver="keyserver.ubuntu.com" id="1C4CBDCDCD2EFD2A" state=present
- name: TEMPLATE | Deploy APT pinning (prevent upgrades from Debian)
template: src=etc/apt/preferences.d/95-percona.j2 dest=/etc/apt/preferences.d/95-percona
- name: APT_REPOSITORY | Add Percona repository
apt_repository: repo='deb {{ percona_repository }} {{ ansible_distribution_release }} main' state=present
- name: APT_RESPOSITORY | Add Percona (src) repository
apt_repository: repo='deb-src {{ percona_repository }} {{ ansible_distribution_release }} main' state=present
# TODO: https://gist.github.com/mbbx6spp/3866962
- name: SHELL | Prepare Percona silent installation (root password)
shell: echo 'percona-server-server-{{ percona_version }} percona-server-server/root_password password {{ mysql_root_password }}' | debconf-set-selections
when: not mysql_exists.stat.exists
- name: SHELL | Prepare Percona silent installation (root password again)
shell: echo 'percona-server-server-{{ percona_version }} percona-server-server/root_password_again password {{ mysql_root_password }}' | debconf-set-selections
when: not mysql_exists.stat.exists
- name: APT | Install Percona
apt: update_cache=yes cache_valid_time=3600 pkg='percona-server-server-{{ percona_version }}' state=latest

View File

@ -7,35 +7,11 @@
fail: msg='IMPOSSIBLE'
when: not "{{ mysql_origin }}_{{ mysql_vendor }}"
- name: APT | Install few MySQL related tools
apt: pkg={{ item }} state=latest
with_items:
- mytop
- percona-toolkit
- python-configparser
- python-mysqldb
- name: STAT | Check if mysql exists
stat: path=/etc/init.d/mysql
register: mysql_exists
changed_when: false
- name: INCLUDE | Install MySQL from default repo
include: 'debian_mysql.yml'
when: mysql_origin == 'default' mysql_vendor == 'mysql'
- name: INCLUDE | Install MariaDB from Debian repo
include: 'debian_mariadb.yml'
when: mysql_origin == 'default' and mysql_vendor == 'mariadb'
- name: INCLUDE | Install MariaDB from MariaDB repo
include: 'mariadb_mariadb.yml'
when: mysql_origin == 'default' and mysql_vendor == 'mariadb'
- name: INCLUDE | Install Percona Server from Percona repo
include: 'percona_percona.yml'
when: mysql_origin == 'percona' and mysql_vendor == 'percona'
- name: TEMPLATE | Deploy daemon configuration
template: src=etc/mysql/conf.d/98-config.cnf.j2 dest=/etc/mysql/conf.d/98-config.cnf
notify: restart mysql

View File

@ -0,0 +1,6 @@
# {{ ansible_managed }}
Explanation: Prevent Debian upgrades on percona packages
Package: *
Pin: release o=Percona Development Team
Pin-Priority: 1001

View File

@ -0,0 +1,17 @@
# -------------------------------------------
# {{ ansible_managed }}
# -------------------------------------------
{% for i in mysql_cnf %}
[{{ i.group_name }}]
{% for c in i.conf %}
{% if c.value is defined %}
{{ c.key }} = {{ c.value }}
{% else %}
{{ c.key }}
{% endif %}
{% endfor %}
{% endfor %}
; vim: set ft=ini :

View File

@ -0,0 +1,8 @@
# ------------------------------------------
# {{ ansible_managed }}
# ------------------------------------------
[client]
user=root
pass={{ mysql_root_password }}