alucepsの日記

ソフトウェアエンジニアをしているおっさんが生きている中でメモしたいと思ったことを記録します。

VagrantとAnsibleでLAMP環境を構築する

構築する予定の環境

name version
CentOS 6.7
Apache 2.2.15
mysql 5.7.11
php 7.0.3

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  # https://github.com/NREL/vagrant-boxes
  config.vm.box = "centos67"
  config.vm.box_url = "https://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.7-x86_64-v20151108.box"

  config.vm.define "web" do |node|
    node.vm.hostname = "play"
    node.vm.network :private_network, ip:"192.168.33.100"
    node.vm.synced_folder "data", "/vagrant"
  end

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "provisioning/playbook.yml"
  end
end

playbook.yml

- hosts: all
  become: yes
  tasks:
    - name: system update
      yum: name=* state=latest

    - name: install repository
      yum: name={{item}}
      with_items:
        - http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
        - http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

    - name: replace repos.d/*.repo
      replace: dest=/etc/yum.repos.d/{{item}} regexp="enabled *= *1" replace="enabled=0"
      with_items:
        - epel.repo
        - remi.repo
        - mysql-community.repo

    - name: install database
      yum: name={{item}} state=present enablerepo=mysql57-community-dmr
      with_items:
        - mysql-community-client
        - mysql-community-server

    - name: install php
      yum: name={{item}} state=present enablerepo=remi-php70
      with_items:
        - php70-php
        - php70-php-mbstring
        - php70-php-gd
        - php70-php-mysqlnd

    - name: symbolic link
      file: src=/usr/bin/php70 dest=/usr/bin/php state=link

    - name: iptables disabled
      service: name={{item}} state=stopped
      with_items:
        - iptables
        - ip6tables

    - name: httpd and mysql start
      service: name={{item}} state=started enabled=yes
      with_items:
        - httpd
        - mysqld