From 2913f6d64882bb9b11297eb6e6e9b8cf0a0b1ba3 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Sat, 9 Jun 2018 08:48:20 +0000 Subject: [PATCH] mariadb fixes --- playbooks/roles/mariadb/README.md | 13 +++--- playbooks/roles/mariadb/defaults/main.yml | 1 - playbooks/roles/mariadb/handlers/main.yml | 1 - playbooks/roles/mariadb/tasks/centos.yml | 7 +++- playbooks/roles/mariadb/tasks/main.yml | 10 +++-- .../tasks/mysql_secure_installation.yml | 42 ++++--------------- .../tasks/{ubuntu.yml => ubuntu-trusty.yml} | 14 +++---- .../roles/mariadb/tasks/ubuntu-xenial.yml | 27 ++++++++++++ .../mariadb/templates/mariadb_centos.repo.j2 | 2 +- .../mariadb/templates/mariadb_ubuntu.list.j2 | 2 +- playbooks/roles/mariadb/vars/main.yml | 3 +- 11 files changed, 60 insertions(+), 62 deletions(-) rename playbooks/roles/mariadb/tasks/{ubuntu.yml => ubuntu-trusty.yml} (63%) create mode 100644 playbooks/roles/mariadb/tasks/ubuntu-xenial.yml diff --git a/playbooks/roles/mariadb/README.md b/playbooks/roles/mariadb/README.md index bc872db5..72e42382 100644 --- a/playbooks/roles/mariadb/README.md +++ b/playbooks/roles/mariadb/README.md @@ -7,6 +7,8 @@ Installs MariaDB ``` CentOS 6 & 7 Ubuntu 14.04 +Ubuntu 16.04 +Debain 9 ``` ## Post install @@ -22,7 +24,7 @@ None MariaDB version: ``` -mariadb_version: 10.0 +mariadb_version: 10.2 ``` Configuration template: @@ -52,13 +54,10 @@ None ``` - hosts: servers roles: - - { role: pcextreme.mariadb } + - { role: mariadb } ``` -## License +## Credits -MIT / BSD +- [Attila van der Velde](https://github.com/vdvm) -## Author Information - -Created by [Attila van der Velde](https://github.com/vdvm) diff --git a/playbooks/roles/mariadb/defaults/main.yml b/playbooks/roles/mariadb/defaults/main.yml index fce5bc00..78831c10 100644 --- a/playbooks/roles/mariadb/defaults/main.yml +++ b/playbooks/roles/mariadb/defaults/main.yml @@ -5,4 +5,3 @@ mysql_conf_tpl: change_me mysql_conf_file: settings.cnf mysql_secure_installation: false -... \ No newline at end of file diff --git a/playbooks/roles/mariadb/handlers/main.yml b/playbooks/roles/mariadb/handlers/main.yml index 7072dbd9..3755d8ce 100644 --- a/playbooks/roles/mariadb/handlers/main.yml +++ b/playbooks/roles/mariadb/handlers/main.yml @@ -1,4 +1,3 @@ --- - name: restart mysql service: name=mysql state=restarted -... \ No newline at end of file diff --git a/playbooks/roles/mariadb/tasks/centos.yml b/playbooks/roles/mariadb/tasks/centos.yml index 2b5ced27..c069aacd 100644 --- a/playbooks/roles/mariadb/tasks/centos.yml +++ b/playbooks/roles/mariadb/tasks/centos.yml @@ -6,5 +6,8 @@ yum: name={{ item }} enablerepo=mariadb state=present with_items: - MariaDB-server - - MySQL-python # required for secure_install -... + - MariaDB-client + +- name: Install MySQLdb Python package for secure installations. + yum: name=MySQL-python state=present + when: mysql_secure_installation and mysql_root_password is defined diff --git a/playbooks/roles/mariadb/tasks/main.yml b/playbooks/roles/mariadb/tasks/main.yml index 8d3e6ea0..6802e7ad 100644 --- a/playbooks/roles/mariadb/tasks/main.yml +++ b/playbooks/roles/mariadb/tasks/main.yml @@ -1,10 +1,12 @@ --- +- include: centos.yml + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version|int >= 6 -- include_tasks: centos.yml - when: ansible_distribution == 'CentOS' +- include: ubuntu-trusty.yml + when: ansible_distribution == 'Ubuntu' and ansible_distribution_version == '14.04' -- include_tasks: ubuntu.yml - when: ansible_distribution == 'Ubuntu' +- include: ubuntu-xenial.yml + when: ansible_distribution == 'Ubuntu' and ansible_distribution_version == '16.04' - name: Add configuration template: src={{ mysql_conf_tpl }} dest={{ mysql_conf_dir[ansible_distribution] }}/{{ mysql_conf_file }} owner=root group=root mode=0644 diff --git a/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml b/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml index 621ab4b0..27d1ca80 100644 --- a/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml +++ b/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml @@ -1,33 +1,22 @@ --- -# Set root password -# UPDATE mysql.user SET Password=PASSWORD('mysecret') WHERE User='root'; -# FLUSH PRIVILEGES; - debug: msg: "{{ mysql_root_password }}" -- name: Set root Password - mysql_user: name=root host={{ item }} password={{ mysql_root_password }} state=present - with_items: - - localhost - ignore_errors: yes - +# create root .my.cnf config file - name: Add .my.cnf template: src=my.cnf.j2 dest=/root/.my.cnf owner=root group=root mode=0600 -- name: display .my.cnf - command: cat /root/.my.cnf - register: details - -- debug: - msg: "{{ details.stdout_lines }}" +# Set root password +# UPDATE mysql.user SET Password=PASSWORD('mysecret') WHERE User='root'; +# FLUSH PRIVILEGES; - name: Set root Password - mysql_user: name=root host={{ item }} password={{ mysql_root_password }} state=present + mysql_user: login_password={{ mysql_root_password }} check_implicit_admin=yes name=root host={{ item }} password={{ mysql_root_password }} state=present with_items: + - localhost - 127.0.0.1 - ::1 - when: run_travis is not defined - name: Reload privilege tables command: 'mysql -ne "{{ item }}"' @@ -53,7 +42,7 @@ - name: Remove test database and access to it command: 'mysql -ne "{{ item }}"' with_items: - - DROP DATABASE if exists test + - DROP DATABASE IF EXISTS test - DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%' changed_when: False when: run_travis is not defined @@ -64,20 +53,3 @@ - FLUSH PRIVILEGES changed_when: False when: run_travis is not defined - -- name: add launchagents folder mac - file: path=~/Library/LaunchAgents state=directory - when: ansible_distribution == 'MacOSX' - -- name: add mysql to mac startup - file: src=/usr/local/opt/mariadb/homebrew.mxcl.mariadb.plist path=~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist state=link force=yes - when: ansible_distribution == 'MacOSX' - -- name: stop mysql mac - command: launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist - when: ansible_distribution == 'MacOSX' - -- name: start mysql mac - command: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist - when: ansible_distribution == 'MacOSX' -... diff --git a/playbooks/roles/mariadb/tasks/ubuntu.yml b/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml similarity index 63% rename from playbooks/roles/mariadb/tasks/ubuntu.yml rename to playbooks/roles/mariadb/tasks/ubuntu-trusty.yml index 5abec54b..56cd0b66 100644 --- a/playbooks/roles/mariadb/tasks/ubuntu.yml +++ b/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml @@ -6,12 +6,6 @@ - name: Add repo key apt_key: id=1BB943DB url=http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xCBCB082A1BB943DB state=present register: mariadb_key - when: ansible_distribution_version | version_compare('16.04', 'lt') - -- name: Add apt key for mariadb for Ubuntu >= 16.04 - apt_key: id=C74CD1D8 url=http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF1656F24C74CD1D8 state=present - register: mariadb_key - when: ansible_distribution_version | version_compare('16.04', 'ge') - name: Update apt cache apt: update_cache=yes @@ -25,5 +19,9 @@ apt: pkg={{ item }} state=present with_items: - mariadb-server - - python-mysqldb # required to set the MySQL password using ansible -... + - mariadb-client + - libmariadbclient18 + +- name: Install MySQLdb Python package for secure installations. + apt: pkg=python-mysqldb state=present + when: mysql_secure_installation and mysql_root_password is defined diff --git a/playbooks/roles/mariadb/tasks/ubuntu-xenial.yml b/playbooks/roles/mariadb/tasks/ubuntu-xenial.yml new file mode 100644 index 00000000..8e834ee8 --- /dev/null +++ b/playbooks/roles/mariadb/tasks/ubuntu-xenial.yml @@ -0,0 +1,27 @@ +--- +- name: Add repo file + template: src=mariadb_ubuntu.list.j2 dest=/etc/apt/sources.list.d/mariadb.list owner=root group=root mode=0644 + register: mariadb_list + +- name: Add repo key + apt_key: id=C74CD1D8 url=http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF1656F24C74CD1D8 state=present + register: mariadb_key + +- name: Update apt cache + apt: update_cache=yes + when: mariadb_list.changed == True or mariadb_key.changed == True + +- name: Unattended package installation + shell: export DEBIAN_FRONTEND=noninteractive + changed_when: false + +- name: Install MariaDB + apt: pkg={{ item }} state=present + with_items: + - mariadb-server + - mariadb-client + - libmariadbclient18 + +- name: Install MySQLdb Python package for secure installations. + apt: pkg=python-mysqldb state=present + when: mysql_secure_installation and mysql_root_password is defined diff --git a/playbooks/roles/mariadb/templates/mariadb_centos.repo.j2 b/playbooks/roles/mariadb/templates/mariadb_centos.repo.j2 index 0a025305..64738cc1 100644 --- a/playbooks/roles/mariadb/templates/mariadb_centos.repo.j2 +++ b/playbooks/roles/mariadb/templates/mariadb_centos.repo.j2 @@ -1,4 +1,4 @@ -# MariaDB {{ mariadb_version }} CentOS {{ ansible_distribution_major_version|int }} repository list +# MariaDB CentOS {{ ansible_distribution_major_version|int }} repository list # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB diff --git a/playbooks/roles/mariadb/templates/mariadb_ubuntu.list.j2 b/playbooks/roles/mariadb/templates/mariadb_ubuntu.list.j2 index dca4e70b..981b4d6b 100644 --- a/playbooks/roles/mariadb/templates/mariadb_ubuntu.list.j2 +++ b/playbooks/roles/mariadb/templates/mariadb_ubuntu.list.j2 @@ -1,4 +1,4 @@ -# MariaDB {{ mariadb_version }} Ubuntu {{ ansible_distribution_release | title }} repository list +# MariaDB Ubuntu {{ ansible_distribution_release | title }} repository list # http://mariadb.org/mariadb/repositories/ deb http://ams2.mirrors.digitalocean.com/mariadb/repo/{{ mariadb_version }}/ubuntu {{ ansible_distribution_release | lower }} main deb-src http://ams2.mirrors.digitalocean.com/mariadb/repo/{{ mariadb_version }}/ubuntu {{ ansible_distribution_release | lower }} main diff --git a/playbooks/roles/mariadb/vars/main.yml b/playbooks/roles/mariadb/vars/main.yml index b7bf4bcf..df81b3b7 100644 --- a/playbooks/roles/mariadb/vars/main.yml +++ b/playbooks/roles/mariadb/vars/main.yml @@ -3,7 +3,6 @@ mysql_conf_dir: "CentOS": /etc/my.cnf.d "Ubuntu": /etc/mysql/conf.d "Debian": /etc/mysql/conf.d - "MacOSX": /usr/local/etc/my.cnf.d mysql_conf_tpl: files/mariadb_config.cnf mysql_secure_installation: True -... \ No newline at end of file +...