Quick MySQL Box Using Vagrant and Ansible
Update July 19, 2014:
The default MySQL Server package in the CentOS repo is ridiculously old (5.1 - MyIASM is the default storage engine). If you need the newest version of MySQL, there is an RPM for the Oracle YUM Repo which will provide you the latest packages. I can't provide you that here because you have to accept Oracles Terms of Service agreement (sorry).
I needed a quick and minimal MySQL box to use for some development work. I didn't want this box to be laden with a full LAMP stack (plus a myriad of other tools PHP'ers seem to need in their endeavors). Unfortunately, I didn't find one. This forced me to create one, which I share with you now.
The Vagrant file is simple:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "2creatives-centos64"
config.vm.box_url = "https://github.com/2creatives/" +
"vagrant-centos/releases/download/v0.1.0/" +
"centos64-x86_64-20131030.box"
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.network "private_network", ip: "192.168.24.42"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.verbose = "vv"
ansible.sudo = true
end
end
And the playbook:
---
- hosts: all
vars:
root_db_password: password
gather_facts: True
tasks:
- name: Install MySQL
yum: name=mysql-server state=installed
- name: Install MySQL-python
yum: name=MySQL-python state=installed
- name: Ensure MySQL is running
service: name=mysqld state=started enabled=true
- name: Ensure IPTables is not running
service: name=iptables state=stopped enabled=false
- name: Copy the my.cnf
copy: src=my.cnf dest=/root/.my.cnf owner=root mode=0600
- name: Update MySQL Root Password
mysql_user: name=root host=$item password=$root_db_password
with_items:
- $ansible_hostname
- 192.168.24.1
- 127.0.0.1
- ::1
- localhost
- name: Annonymous Users not in MySQL
mysql_user: name='' host=$item state=absent
with_items:
- localhost
- $inventory_hostname
- name: Test Database is Removed
mysql_db: name=test state=absent
And finally, you will notice we are copying a local instance of my.cnf
to the virtual machine:
[client]
user=root
password=password
As I said, it's very minimal.
You can clone the deployment from this repository: https://github.com/rclayton/vagrant-mysql
Also, I want to thank Lorin Hochstein for a portion of the Ansible config (particularly saving me some time on removing some of the default gruff.
Stumbling my way through the great wastelands of enterprise software development.