Skip to content

Commit

Permalink
Create Mysql playbook
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dzydzany authored and rxaviers committed Dec 3, 2014
1 parent 1a056b4 commit 85aced8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
tasks:
- include: common/bootstrap.yml


- name: configure and deploy the webservers and application code
hosts: webservers
remote_user: root
Expand All @@ -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
Expand All @@ -22,4 +24,5 @@
- include: web/rails.yml

handlers:
- include: web/mysql-server-handlers.yml
- include: web/postgresql-handlers.yml
24 changes: 24 additions & 0 deletions web/mysql-server-handlers.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions web/mysql-server.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 85aced8

Please sign in to comment.