Skip to content
This repository was archived by the owner on Mar 5, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ministerial-data-cabinet-office
#OS Artifacts
.DS_STORE

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 2 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vagrant/

22 changes: 22 additions & 0 deletions server/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Eddie Abou-Jaoude

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

57 changes: 57 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Vagrant Ansible Docker

Vagrant with Ansible, Docker, Xdebug

---

## Contains

* PHP
* MySQL
* Apache
* Docker
* MySQL
* Elasticsearch
* Redis
* Npm
* Bower
* Grunt
* Express
* Socket.io
* Ruby
* Xdebug (debugging code) - not recommended to use with Blackfire

## Dependencies

* Vagrant

---

## Usage

1. Clone repo and add to root of your project
2. Vagrant up (use `--debug` for more verbose output from **vagrant**)
3. Access **web** on `http://192.168.33.90/`
4. Access **mysql** on `192.168.33.90:3306`
5. 4. Access **elasticsearch** on `192.168.33.90:9200`
6. etc...

---

## Customisation


### System wide **apt** packages

Edit `ansible/vars/all.yml` and add to collect on line 4, looks like `packages: [vim, htop, iotop]`

*Or variables, mysql passwords etc*

### What **ansible** installs (eg. nginx or apache)

Edit `ansible/playbook.yml` *comment/uncomment* **roles** collection.


### What **docker** containers are installed

Edit `ansible/roles/docker/tasks/main.yml` and add includes for extra containers.
58 changes: 58 additions & 0 deletions server/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
##################################################
# Generated by phansible.com
##################################################

#If your Vagrant version is lower than 1.5, you can still use this provisioning
#by commenting or removing the line below and providing the config.vm.box_url parameter,
#if it's not already defined in this Vagrantfile. Keep in mind that you won't be able
#to use the Vagrant Cloud and other newer Vagrant features.
Vagrant.require_version ">= 1.5"

# Check to determine whether we're on a windows or linux/os-x host,
# later on we use this to launch ansible in the supported way
# source: https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable? exe
}
end
return nil
end
Vagrant.configure("2") do |config|

config.vm.provider :virtualbox do |v|
v.name = "muti"
v.customize [
"modifyvm", :id,
"--name", "muti",
"--memory", 1024,
"--natdnshostresolver1", "on",
"--cpus", 2,
]
end

config.vm.box = "ubuntu/trusty64"

config.vm.network :private_network, ip: "192.168.33.90"
config.ssh.forward_agent = true

#############################################################
# Ansible provisioning (you need to have ansible installed)
#############################################################

if which('ansible-playbook')
config.vm.provision "ansible" do |ansible|
ansible.playbook = "./ansible/playbook.yml"
ansible.inventory_path = "./ansible/inventories/dev"
ansible.limit = 'all'
end
else
config.vm.provision :shell, path: "./ansible/windows.sh", args: ["default"]
end


config.vm.synced_folder "../", "/vagrant", type: "nfs"
end
2 changes: 2 additions & 0 deletions server/ansible/inventories/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[phansible-web]
192.168.33.90
1 change: 1 addition & 0 deletions server/ansible/playbook.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
192.168.33.90
15 changes: 15 additions & 0 deletions server/ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- hosts: all
sudo: true
vars_files:
- vars/all.yml
roles:
- server
- vagrant_local
- apache
- php
- xdebug
- docker
- npm
- ruby
- app
3 changes: 3 additions & 0 deletions server/ansible/roles/apache/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart apache
service: name=apache2 enabled=yes state=restarted
29 changes: 29 additions & 0 deletions server/ansible/roles/apache/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Install Apache
sudo: yes
apt: pkg=apache2 state=latest

- name: Install Apache Modules
apache2_module: state=present name={{ item }}
notify: restart apache
with_items:
- rewrite
- vhost_alias
- headers
- expires
- filter

- shell: apache2 -v
register: apache_version

- name: Change default apache2.4 site
sudo: yes
template: src=vhost24.conf.tpl dest=/etc/apache2/sites-available/000-default.conf
notify: restart apache
when: apache_version.stdout.find('Apache/2.4.') != -1

- name: Change default apache2.2 site
sudo: yes
template: src=vhost22.conf.tpl dest=/etc/apache2/sites-available/default
notify: restart apache
when: apache_version.stdout.find('Apache/2.2.') != -1
14 changes: 14 additions & 0 deletions server/ansible/roles/apache/templates/vhost22.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Default Apache virtualhost template

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot {{ apache.docroot }}
ServerName {{ apache.servername }}

<Directory {{ apache.docroot }}>
AllowOverride All
Options -Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
13 changes: 13 additions & 0 deletions server/ansible/roles/apache/templates/vhost24.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Default Apache virtualhost template

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot {{ apache.docroot }}
ServerName {{ apache.servername }}

<Directory {{ apache.docroot }}>
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
5 changes: 5 additions & 0 deletions server/ansible/roles/app/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# application tasks to be customized and to run after the main provision
- name: update file db
sudo: yes
shell: updatedb
7 changes: 7 additions & 0 deletions server/ansible/roles/docker/tasks/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: elasticsearch container
docker:
name: elasticsearch
image: elasticsearch
state: started
ports:
- "9200:9200"
13 changes: 13 additions & 0 deletions server/ansible/roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: install pip
shell: curl https://bootstrap.pypa.io/get-pip.py | python -

- name: install docker py
shell: pip install docker-py

- name: install docker
shell: curl -sSL https://get.docker.com/ | sh && sudo usermod -aG docker vagrant

- include: mysql.yml
- include: postgres.yml
- include: redis.yml
- include: elasticsearch.yml
8 changes: 8 additions & 0 deletions server/ansible/roles/docker/tasks/mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: mysql container
docker:
name: mysql
image: mysql
state: started
env: "MYSQL_ROOT_PASSWORD={{ mysql.root_password }}"
ports:
- "3306:3306"
7 changes: 7 additions & 0 deletions server/ansible/roles/docker/tasks/postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: postgres container
docker:
name: postgres
image: postgres
state: started
ports:
- "5432:5432"
7 changes: 7 additions & 0 deletions server/ansible/roles/docker/tasks/redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: redis container
docker:
name: redis
image: redis
state: started
ports:
- "6379:6379"
3 changes: 3 additions & 0 deletions server/ansible/roles/mysql/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart mysql
service: name=mysql enabled=yes state=restarted
43 changes: 43 additions & 0 deletions server/ansible/roles/mysql/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# Retrieve the current hostname, because {{ ansible_hostname }} still contains the old name
- shell: hostname
register: current_hostname

- name: mysql | Install MySQL Packages
sudo: yes
apt: pkg={{ item }} state=latest
with_items:
- mysql-server
- mysql-client
- python-mysqldb

- name: mysql | Update root password for all root accounts
mysql_user: name=root host={{ item }} check_implicit_admin=yes password={{ mysql.root_password }} login_user=root login_password={{ mysql.root_password }}
with_items:
- "{{ current_hostname.stdout | lower }}"
- 127.0.0.1
- ::1
- localhost
- 192.168.33.1

- name: mysql | Create databases
mysql_db: name={{ mysql.database }} state=present login_user=root login_password={{ mysql.root_password }}

- name: mysql | Import dump
mysql_db: name={{ mysql.database }} state=import login_user=root login_password={{ mysql.root_password }} target=/vagrant/{{ mysql.dump }}
when: mysql.dump

- name: mysql | Ensure anonymous users are not in the database
mysql_user: name='' host={{ item }} state=absent login_user=root login_password={{ mysql.root_password }}
with_items:
- localhost
- "{{ current_hostname.stdout | lower }}"

- name: mysql | Create users
mysql_user: name={{ mysql.user }} password={{ mysql.password }} priv=*.*:ALL state=present login_user=root login_password={{ mysql.root_password }}

- name: do not bind to localhost
lineinfile: dest=/etc/mysql/my.cnf
regexp='bind-address'
line='bind-address = 0.0.0.0'
notify: restart mysql
3 changes: 3 additions & 0 deletions server/ansible/roles/nginx/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart nginx
service: name=nginx enabled=yes state=restarted
9 changes: 9 additions & 0 deletions server/ansible/roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Install Nginx
sudo: yes
apt: pkg=nginx state=latest

- name: Change default nginx site
sudo: yes
template: src=default.tpl dest=/etc/nginx/sites-available/default
notify: restart nginx
27 changes: 27 additions & 0 deletions server/ansible/roles/nginx/templates/default.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server {
listen 80;

root {{ nginx.docroot }};
index index.html index.php;

server_name {{ nginx.servername }};

location / {
try_files $uri $uri/ /index.php?$query_string;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
10 changes: 10 additions & 0 deletions server/ansible/roles/npm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: install npm
apt: pkg=npm state=present

- name: install global node packages
npm: name={{item}} global=yes
with_items:
- bower
- grunt-cli
- express
- socket.io
3 changes: 3 additions & 0 deletions server/ansible/roles/php/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart php5-fpm
service: name=php5-fpm enabled=yes state=restarted
Loading