Infrastructure 2017-09-26

Building a Vagrant Development Environment (CentOS7.3) with Ansible

Configure Vagrant development environments using Ansible automation with PHP, Ruby, Nginx, MySQL, and Redis infrastructure.

Read in: ja
Building a Vagrant Development Environment (CentOS7.3) with Ansible

Overview

We will build a development environment on CentOS 7.3 using Vagrant and Ansible.

Environment

Setup

This directory structure somewhat mimics best practices.

ansible/
├── group_vars
│   └── vagrant.yml
├── host
├── roles
│   ├── common
│   │   └── tasks
│   │       ├── add_remi_repo.yml
│   │       ├── install_common.yml
│   │       ├── install_epel_release.yml
│   │       └── main.yml
│   ├── composer
│   │   └── tasks
│   │       ├── install_composer.yml
│   │       └── main.yml
│   ├── mailcatcher
│   │   └── tasks
│   │       ├── install_mailcatcher.yml
│   │       └── main.yml
│   ├── mysql
│   │   └── tasks
│   │       ├── install_mysql.yml
│   │       └── main.yml
│   ├── nginx
│   │   ├── tasks
│   │   │   ├── install_nginx.yml
│   │   │   └── main.yml
│   │   └── templates
│   │       ├── bmf-tech.com.conf
│   │       └── localdev.conf
│   ├── php
│   │   └── tasks
│   │       ├── install_php.yml
│   │       └── main.yml
│   ├── python
│   │   └── tasks
│   │       ├── install_python.yml
│   │       └── main.yml
│   ├── redis
│   │   └── tasks
│   │       ├── install_redis.yml
│   │       └── main.yml
│   └── ruby
│       └── tasks
│           ├── install_ruby.yml
│           └── main.yml
├── site.retry
└── site.yml

The source is available on github - my-ansible-vagrant, so please refer to that for the contents.

Here is how the Vagrantfile looks.

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

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "centos7.3"

  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.synced_folder "/path/to/directory", "/var/www/html",:mount_options => ["dmode=775,fmode=664"]

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "ansible/site.yml"
    ansible.inventory_path = "ansible/host"
    ansible.limit = 'all'
  end

  config.vm.network :private_network, ip: "192.168.33.10"
  config.vm.hostname = "localdev"
  config.hostsupdater.aliases = ["localdev"]
end

You can run provisioning with vagrant provision.

Additional Notes

Is the php-fpm configuration incorrect?

To use PHP 7 with Nginx, it seems necessary to use something called php-fpm as a CGI, which can be tricky. If you encounter a 500 error, reviewing the configuration in this area might resolve the issue.

Building a Laravel Development Environment on CENTOS 7 with NGINX+PHP-FPM+PHP7 on VAGRANT (Part 1)

Unable to access the IP address specified in the Vagrantfile

Although I was able to build it, I struggled to access the IP specified in the Vagrantfile. After reviewing the IP settings and adjusting the firewalld configuration based on the following articles, I managed to resolve the issue. (It seems I encountered a bug in vagrant 1.9.0.)

Impressions

CentOS 7 has quite a few differences from previous OS versions, but I didn't struggle too much with those adjustments. Instead, I had more trouble with the compatibility of MySQL 5.7. It works for now, but I think there is still room for improvement.

References

Tags: Ansible CentOS Vagrant
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles