Quick MySQL Box UsingVagrant and Ansible_MySQL

WBOY
發布: 2016-06-01 13:06:12
原創
1138 人瀏覽過

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: 3306config.vm.network "private_network", ip: "192.168.24.42"config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", "2048"]endconfig.vm.provision "ansible" do |ansible|ansible.playbook = "playbook.yml"ansible.verbose = "vv"ansible.sudo = trueendend
登入後複製

And the playbook:

---- hosts: allvars:root_db_password: passwordgather_facts: Truetasks:- name: Install MySQLyum: name=mysql-server state=installed- name: Install MySQL-pythonyum: name=MySQL-python state=installed- name: Ensure MySQL is runningservice: name=mysqld state=started enabled=true- name: Ensure IPTables is not runningservice: name=iptables state=stopped enabled=false- name: Copy the my.cnfcopy: src=my.cnf dest=/root/.my.cnf owner=root mode=0600- name: Update MySQL Root Passwordmysql_user: name=root host=$item password=$root_db_passwordwith_items:- $ansible_hostname- 192.168.24.1- 127.0.0.1- ::1- localhost- name: Annonymous Users not in MySQLmysql_user: name='' host=$item state=absentwith_items:- localhost- $inventory_hostname- name: Test Database is Removedmysql_db: name=test state=absent
登入後複製

And finally, you will notice we are copying a local instance ofmy.cnfto the virtual machine:

[client]user=rootpassword=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 thankLorin Hochsteinfor a portion of the Ansible config (particularly saving me some time on removing some of the default gruff.

Richard Clayton–Unrepentant Thoughts on Software and Management.

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板