This guide will show how to setup Nginx+php5-fpm development VM’s using Vagrant with Ansible as provisioner with added bonus using Ansible Galaxy for roles.
Requirements:
Ubuntu 12.04 or higher
Virtualbox 4.14+
Vagrant 1.4.3
Ansible 1.4+
Setup Ansible using VirtualEnv to isolate working environment:
$ virtualenv ansi_env $ cd ansi_env $ source bin/activate $ pip install ansible
Assuming Virtualbox and vagrant are already installed:
$ mkdir ~/vagrant $ cd ~/vagrant $ vagrant box add precise64 http://files.vagrantup.com/precise64.box $ git clone https://github.com/cocoy/vagrant_ansible.git $ cd vagrant_ansible $ vagrant up web
The commands will launch vagrant web vm with simply nginx installed.
The nice part is using Ansible Galaxy by adding more roles to speedup environment setup.
$ export ANSIBLE_ROLES_PATH=playbooks/roles/ $ ansible-galaxy install nbz4live.php-fpm
Edit playbook/web.xml under roles add the line below:
--- - hosts: all roles: - common - nginx - nbz4live.php-fpm
Now let’s provision the web server with php-fpm added:
$ vagrant provision web
Now we can see nginx + php5-fpm installed. Let’s try adding site config and index.php then.
--- - hosts: all roles: - common - nginx - nbz4live.php-fpm - nginx-fpm-setup
This time just run ansible provision web and hit localhost:8080 on your browser.
In summary Ansible Galaxy can ease our setup and ready to use Ansible roles!