From 5d6abb0dda58b36c479cb9f9ee5e182f4267e714 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 21 Aug 2015 11:24:37 +0200 Subject: [PATCH] Role organization: Delete useless files percona-xtrbackup is optional on Wheezy (unless you use percona apt) better organization in mysql vendors --- README.md | 3 +- defaults/main.yml | 1 + tasks/install/main.yml | 30 ++++++++----------- .../default.yml} | 0 .../upstream.yml} | 2 +- .../{default_mysql.yml => mysql/default.yml} | 0 tasks/install/percona/apt.yml | 14 +++++++++ .../upstream.yml} | 8 +++++ tasks/main.yml | 3 -- tests/group_vars/all | 1 + 10 files changed, 39 insertions(+), 23 deletions(-) rename tasks/install/{default_mariadb.yml => mariadb/default.yml} (100%) rename tasks/install/{upstream_mariadb.yml => mariadb/upstream.yml} (93%) rename tasks/install/{default_mysql.yml => mysql/default.yml} (100%) create mode 100644 tasks/install/percona/apt.yml rename tasks/install/{upstream_percona.yml => percona/upstream.yml} (75%) create mode 100644 tests/group_vars/all diff --git a/README.md b/README.md index 0f4543a..c729843 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ MySQL vendors for Debian Ansible role ====================================== -Install and configure MySQL or MariaDB or Percona Server. Create users and databases. +Install and configure MySQL or MariaDB or Percona Server. Manage replication (master/slave). Create users and databases. Requirements ------------ @@ -13,6 +13,7 @@ Role Variables - `mysql_origin`: origin of the package ("default" or "upstream") - `mysql_vendor`: "mysql", "mariadb" or "percona" +- `mysql_use_percona_repository`: use percona APT repository (automatic setted to true if you use "percona" as `mysql_vendor`). You need to set "true" on Wheezy if you want to install percona-xtrabackup. ### Configuration diff --git a/defaults/main.yml b/defaults/main.yml index f02f688..1a0da7f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,6 +6,7 @@ mysql_origin: 'upstream' mysql_vendor: 'mariadb' mysql_root_password: 'change_me_NOW' +mysql_use_percona_repository: false # ------------------------------------- # Configuration diff --git a/tasks/install/main.yml b/tasks/install/main.yml index d65df9a..558d2e5 100644 --- a/tasks/install/main.yml +++ b/tasks/install/main.yml @@ -1,7 +1,7 @@ --- - name: FAIL | If config asked is impossible - fail: msg="config asked is impossible origin -> {{ mysql_origin }} vendor -> {{ mysql_vendor }}" + fail: msg="config asked is impossible" when: > not ( (mysql_origin == 'default' and mysql_vendor == 'mysql') or @@ -10,33 +10,24 @@ (mysql_origin == 'upstream' and mysql_vendor == 'percona') ) -- name: APT_KEY | Install Percona key - apt_key: keyserver="keyserver.ubuntu.com" id="1C4CBDCDCD2EFD2A" state=present -#apt_key: keyserver="keys.gnupg.net" 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 +- name: APT | Install Percona Xtrabackup + include: percona/apt.yml + when: mysql_use_percona_repository - name: INCLUDE | Install MySQL from default repo - include: 'default_mysql.yml' + include: 'mysql/default.yml' when: mysql_origin == 'default' and mysql_vendor == 'mysql' - name: INCLUDE | Install MariaDB from Debian repo - include: 'default_mariadb.yml' + include: 'mariadb/default.yml' when: mysql_origin == 'default' and mysql_vendor == 'mariadb' and ansible_distribution_major_version > 7 - name: INCLUDE | Install MariaDB from MariaDB repo - include: 'upstream_mariadb.yml' + include: 'mariadb/upstream.yml' when: mysql_origin == 'upstream' and mysql_vendor == 'mariadb' - name: INCLUDE | Install Percona Server from Percona repo - include: 'upstream_percona.yml' + include: 'percona/upstream.yml' when: mysql_origin == 'upstream' and mysql_vendor == 'percona' - name: APT | Install few MySQL related tools @@ -45,6 +36,9 @@ - mytop - percona-toolkit - python-mysqldb - - percona-xtrabackup - mysqltuner +- name: APT | Install Percona Xtrabackup + apt: pkg=percona-xtrabackup state=present + when: ansible_distribution_major_version > 7 or mysql_use_percona_repository + diff --git a/tasks/install/default_mariadb.yml b/tasks/install/mariadb/default.yml similarity index 100% rename from tasks/install/default_mariadb.yml rename to tasks/install/mariadb/default.yml diff --git a/tasks/install/upstream_mariadb.yml b/tasks/install/mariadb/upstream.yml similarity index 93% rename from tasks/install/upstream_mariadb.yml rename to tasks/install/mariadb/upstream.yml index 77e08d8..2ec3dbb 100644 --- a/tasks/install/upstream_mariadb.yml +++ b/tasks/install/mariadb/upstream.yml @@ -10,5 +10,5 @@ apt_repository: repo='deb-src {{ mariadb_repository }} {{ ansible_distribution_release }} main' state=present - name: INCLUDE | Normal Install - include: default_mariadb.yml + include: default.yml diff --git a/tasks/install/default_mysql.yml b/tasks/install/mysql/default.yml similarity index 100% rename from tasks/install/default_mysql.yml rename to tasks/install/mysql/default.yml diff --git a/tasks/install/percona/apt.yml b/tasks/install/percona/apt.yml new file mode 100644 index 0000000..f1adee7 --- /dev/null +++ b/tasks/install/percona/apt.yml @@ -0,0 +1,14 @@ +--- + +- name: APT_KEY | Install Percona key + apt_key: keyserver="keyserver.ubuntu.com" id="1C4CBDCDCD2EFD2A" state=present + +- name: TEMPLATE | Deploy APT pinning (prevent upgrades from Debian) + template: src=../../../templates/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 + diff --git a/tasks/install/upstream_percona.yml b/tasks/install/percona/upstream.yml similarity index 75% rename from tasks/install/upstream_percona.yml rename to tasks/install/percona/upstream.yml index 1f8a3cf..aa7b08d 100644 --- a/tasks/install/upstream_percona.yml +++ b/tasks/install/percona/upstream.yml @@ -1,5 +1,13 @@ --- +# We prevent double include +- name: INCLUDE | Add percona APT repository + include: apt.yml + when: not mysql_use_percona_repository + +- name: SET_FACT | We use percona repository + set_fact: mysql_use_percona_repository=true + - name: DEBCONF | Prepare MySQL silent installation (root password) debconf: name='percona-server-server-{{ percona_version }}' question='percona-server-server/root_password' vtype='password' value='{{ mysql_root_password }}' when: not mysql_exists.stat.exists diff --git a/tasks/main.yml b/tasks/main.yml index 9d57a44..673928e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,5 @@ --- -- name: INCLUDE_VARS | Related to Debian version - include_vars: "{{ ansible_distribution_release }}.yml" - - name: STAT | Check if mysql exists stat: path=/etc/init.d/mysql register: mysql_exists diff --git a/tests/group_vars/all b/tests/group_vars/all new file mode 100644 index 0000000..bfb0487 --- /dev/null +++ b/tests/group_vars/all @@ -0,0 +1 @@ +mysql_use_percona_repository: true