From 4955653d486706f8275ef630b148ecb8c8506476 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sun, 12 Jul 2015 10:42:46 +0200 Subject: [PATCH] first commit --- README.md | 38 +++++++++ defaults/main.yml | 39 +++++++++ handlers/main.yml | 2 + meta/main.yml | 133 ++++++++++++++++++++++++++++++ tasks/install_default_mariadb.yml | 0 tasks/install_default_mysql.yml | 0 tasks/install_percona_percona.yml | 0 tasks/installmariadb_mariadb.yml | 0 tasks/main.yml | 56 +++++++++++++ tasks/secure.yml | 21 +++++ vars/jessie.yml | 8 ++ vars/main.yml | 9 ++ vars/wheezy.yml | 9 ++ 13 files changed, 315 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/install_default_mariadb.yml create mode 100644 tasks/install_default_mysql.yml create mode 100644 tasks/install_percona_percona.yml create mode 100644 tasks/installmariadb_mariadb.yml create mode 100644 tasks/main.yml create mode 100644 tasks/secure.yml create mode 100644 vars/jessie.yml create mode 100644 vars/main.yml create mode 100644 vars/wheezy.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..7fbf6e0 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,39 @@ +--- + +# ------------------------------------- +# Setup +# ------------------------------------- +mysql_origin: 'mariadb' +mysql_vendor: "mariadb" +mysql_root_password: 'change_me_NOW' + +# ------------------------------------- +# Configuration +# ------------------------------------- +mysql_cnf: + - group_name: 'mysqld' + conf: + - key: 'innodb_file_per_table' + value: 1 + - key: 'innodb_buffer_pool_size' # 60% available RAM :) + value: '{{ (ansible_memtotal_mb * 0.6) | round | int }}M' + +# ------------------------------------- +# Database / Users +# ------------------------------------- +mysql_databases: [] +mysql_users: [] + +# ------------------------------------- +# MariaDB +# ------------------------------------- +mariadb_version: '10.1' # (5.5, 10.0, 10.1) +# See: http://mariadb.org/mariadb/repositories/ +mariadb_repository: "http://ftp.igh.cnrs.fr/pub/mariadb/repo/{{ mariadb_version }}/debian" + +# ------------------------------------- +# Percona +# ------------------------------------- +percona_version: '5.6' +percona_repository: 'http://repo.percona.com/apt' + diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..050cdd1 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for . diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..b98e3f6 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,133 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. Only + # dependencies available via galaxy should be listed here. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/tasks/install_default_mariadb.yml b/tasks/install_default_mariadb.yml new file mode 100644 index 0000000..e69de29 diff --git a/tasks/install_default_mysql.yml b/tasks/install_default_mysql.yml new file mode 100644 index 0000000..e69de29 diff --git a/tasks/install_percona_percona.yml b/tasks/install_percona_percona.yml new file mode 100644 index 0000000..e69de29 diff --git a/tasks/installmariadb_mariadb.yml b/tasks/installmariadb_mariadb.yml new file mode 100644 index 0000000..e69de29 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..2c118ac --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,56 @@ +--- + +- name: INCLUDE_VARS | Related to Debian version + include_vars: "{{ ansible_distribution_release }}.yml" + +- name: FAIL | Check if packet is available + 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 + +- name: TEMPLATE Create .my.cnf for root + template: src=root/my.cnf dest=/root/.my.cnf owner=root group=root mode=0600 backup=yes + +- name: INCLUDE | Secure install + include: 'secure.yml' + +- name: MYSQL_DB | Create databases + mysql_db: name={{ item }} state=present + with_items: mysql_databases + +- name: MYSQL_USER | Manages users... + mysql_user: name={{ item.name }} password={{ item.password }} priv={{ item.priv }} state=present + with_items: mysql_users + diff --git a/tasks/secure.yml b/tasks/secure.yml new file mode 100644 index 0000000..c0401d4 --- /dev/null +++ b/tasks/secure.yml @@ -0,0 +1,21 @@ +--- + +- name: MYSQL_USER | Update mysql root password for all root accounts + mysql_user: name=root host={{ item }} password={{ mysql_root_password }} + with_items: + - "{{ ansible_hostname }}" + - 127.0.0.1 + - ::1 + - localhost + +- name: MYSQL_USER | Remove all anonymous users + mysql_user: name='' host={{ item }} state=absent + with_items: + - "{{ ansible_hostname }}" + - 127.0.0.1 + - ::1 + - localhost + +- name: MYSQL_DB | Remove the test database + mysql_db: name=test state=absent + diff --git a/vars/jessie.yml b/vars/jessie.yml new file mode 100644 index 0000000..5d33755 --- /dev/null +++ b/vars/jessie.yml @@ -0,0 +1,8 @@ +# origin_package +default_mariadb: true + +# origin_available_version +mariadb_available_version: + - '10.0' + + diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..a4ce68b --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,9 @@ +--- + +default_mysql: true +mariadb_mariadb: true +percona_percona: true + +percona_available_versions: + - '5.5' + - '5.6' diff --git a/vars/wheezy.yml b/vars/wheezy.yml new file mode 100644 index 0000000..0bfedff --- /dev/null +++ b/vars/wheezy.yml @@ -0,0 +1,9 @@ +# origin_package +default_mariadb: false + +# origin_available_version +mariadb_available_version: + - '5.5' + - '10.0' + +