From 1a138b3b46c8bb1925bb7979d98918487a20bbe7 Mon Sep 17 00:00:00 2001 From: Nikola Vidovic Date: Sat, 1 Nov 2014 20:26:02 +0100 Subject: [PATCH] Create Mysql playbook - Install MySL server and set password for root user from local environment variable. - Continue ansible run if mysql_user fails. Password is already configured at first run. - Remove debuging from mysql playbook and rename mysql password setup task. - Change mysql data folder setting, move mysql data folder and restart required service. - Cheack if apparmor is installed and reconfigure if it does. - Move mysql playbook to webservers section. - Change password variable to mysql_root_passwd. Fixes #11 Closes #35 --- site.yml | 3 +++ web/mysql-server-handlers.yml | 24 ++++++++++++++++++++++++ web/mysql-server.yml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 web/mysql-server-handlers.yml create mode 100644 web/mysql-server.yml diff --git a/site.yml b/site.yml index 3982990..05b67d7 100644 --- a/site.yml +++ b/site.yml @@ -5,6 +5,7 @@ tasks: - include: common/bootstrap.yml + - name: configure and deploy the webservers and application code hosts: webservers remote_user: root @@ -13,6 +14,7 @@ - include: web/deploy.yml - include: web/fastcgi.yml - include: web/git.yml + - include: web/mysql-server.yml - include: web/php.yml - include: web/postgresql.yml - include: web/ruby.yml @@ -22,4 +24,5 @@ - include: web/rails.yml handlers: + - include: web/mysql-server-handlers.yml - include: web/postgresql-handlers.yml diff --git a/web/mysql-server-handlers.yml b/web/mysql-server-handlers.yml new file mode 100644 index 0000000..507d516 --- /dev/null +++ b/web/mysql-server-handlers.yml @@ -0,0 +1,24 @@ +--- + +- name: Restart mysql + action: service name=mysql state=restarted + +- name: Move mysql data folder + command: echo "Starting to move MySQL data folder" + notify: Stop mysql service + +- name: Stop mysql service + action: service name=mysql state=stopped + notify: Move mysql data + +- name: Move mysql data + command: mv /var/lib/mysql /data/ + notify: Start mysql service + +- name: Start mysql service + service: name=mysql state=started + +- name: Restart apparmor service + service: name=mysql state=stopped + service: name=apparmor state=restarted + notify: Start mysql service diff --git a/web/mysql-server.yml b/web/mysql-server.yml new file mode 100644 index 0000000..f7692e2 --- /dev/null +++ b/web/mysql-server.yml @@ -0,0 +1,33 @@ +--- + +- name: Install mysql-server package + apt: name=mysql-server update_cache=yes + +- name: Install python-mysqldb module required by Ansible + apt: name=python-mysqldb update_cache=yes + +- name: Configure mysql root user pass + mysql_user: name=root password="{{ lookup('env','mysql_root_passwd') }}" + ignore_errors: yes + +- name: Create /data/mysql folder + file: path=/data/mysql state=directory owner=mysql group=mysql + +- name: Change mysql data folder + lineinfile: dest=/etc/mysql/my.cnf line='datadir = /data/mysql' + regexp='^datadir' + notify: Move mysql data folder + +- name: Test if apparmor exists + stat: path=/etc/init.d/apparmor + register: apparmor_installed + +- name: Fix apparmor configuration for mysql + lineinfile: + regexp='{{ item.apparmor }}' backrefs=yes line='{{ item.apparmor_line }}' dest=/etc/apparmor.d/usr.sbin.mysqld + with_items: + - { apparmor: '^ /var/lib/mysql/ r\,', apparmor_line: ' /data/mysql/ r,' } + - { apparmor: '^ /var/lib/mysql/\*\* rwk\,', apparmor_line: ' /data/mysql/** rwk,' } + + notify: Restart apparmor service + when: apparmor_installed.stat.exists