Ansible Project Deploy

I decided to move all of my websites and projects to an EC2 Apache virtual host. Considering that I already had all of my websites repoed in GitHub, I wanted to have an easy way to manage pushing out changes to the server. I decided to design a generic set of Ansible playbooks that could be included as a Git Submodule for each website and with minimal configuration build and push out all changes.

There are two build steps in Jenkins that handle then entire process:

git submodule add https://github.com/mcred/Ansible-Project-Deploy ./ansible/
touch ./ansible/inventory/group_vars/all.yaml
echo '---' >> ./ansible/inventory/group_vars/all.yaml
echo 'ec2_instance_name: "HOST_BOX_NAME"' >> ./ansible/inventory/group_vars/all.yaml
echo 'full_domain_path: "/var/www/vhosts/YOURDOMAIN.com"' >> ./ansible/inventory/group_vars/all.yaml
echo 'composer_build: false' >> ./ansible/inventory/group_vars/all.yaml

and then:

#!/bin/bash

set -u # Variables must be explicit
set -e # If any command fails, fail the whole thing
set -o pipefail

export PATH=$PATH:/usr/local/bin

cp ansible_config.yaml ./ansible/inventory/group_vars/all.yaml
cp ~/.ssh/mypemfile.pem ./ansible/inventory/ansible-deploy-key.pem
cp ~/.ssh/aws_keys ./ansible/inventory

cd ansible
bash deploy.sh

Check it out on GitHub