Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Vagrant support
  • Loading branch information
drybjed committed Feb 17, 2014
1 parent 5713691 commit e9203b4
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
/inventory
/inventory-*
/*.sh
/.vagrant

# Created by http://gitignore.io

Expand Down
48 changes: 48 additions & 0 deletions Vagrantfile
@@ -0,0 +1,48 @@
# -*- mode: ruby -*-
# vi: set ft=ruby

# Vagrantfile for ginas project
# https://github.com/drybjed/ginas/

VAGRANTFILE_API_VERSION = '2'

DOMAIN = '.nat.example.com'
NETWORK = '192.168.50.'
NETMASK = '255.255.255.0'

# Source: https://github.com/drybjed/vagrant-debian-wheezy-64/tree/ginas
DEFAULT_BOX = 'debian-wheezy-amd64-netinst'
DEFAULT_BOX_URL = 'https://dl.dropboxusercontent.com/u/55426468/debian-wheezy-amd64-netinst.box'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = DEFAULT_BOX
config.vm.box_url = DEFAULT_BOX_URL

# LEMP webserver (Linux, nginx, MySQL, PHP5)
config.vm.define :web do |web|
web.vm.hostname = 'web' + DOMAIN
web.vm.network :private_network, ip: NETWORK + "10", :netmask => NETMASK
end

# MySQL server with PHPMyAdmin
config.vm.define :db do |db|
db.vm.hostname = 'db' + DOMAIN
db.vm.network :private_network, ip: NETWORK + "20", :netmask => NETMASK
end

# Ansible Controller
config.vm.define :master do |master|
master.vm.hostname = 'master' + DOMAIN
master.vm.network :private_network, ip: NETWORK + "2", :netmask => NETMASK

config.vm.provision "ansible" do |ansible|
ansible.host_key_checking = false
ansible.inventory_path = "contrib/vagrant/inventory"
ansible.playbook = "playbooks/site.yml"
end
end

end


60 changes: 60 additions & 0 deletions contrib/vagrant/inventory/group_vars/vagrant.yml
@@ -0,0 +1,60 @@
---
# host group: vagrant

# Default deployment user, database
global_vagrant_deploy: 'deploy'

# Default password
global_vagrant_password: 'vagrant'

# vagrant local network
global_vagrant_network: '192.168.50.0/24'

# vagrant manages the network interfaces by itself, so let's get out of the way
interfaces: False

# Enable local mail on each host
postfix: [ 'local' ]

# Default admin accounts (vagrant and your username)
auth_admin_accounts:
- 'vagrant'
- '{{ lookup("env","USER") }}'

# Install additional packages in the vagrant group
apt_group_packages: [ 'mysql-client' ]

# root account configuration - set shell to /bin/zsh and install custom dotfiles
# root should be in it's own hash variable
users_root:
- name: 'root'
shell: '/bin/zsh'
dotfiles: True

# Configuration of default accounts on all hosts in vagrant group
users_default:

# vagrant account
- name: 'vagrant'
shell: '/bin/zsh'
groups: 'admins'
dotfiles: True
sshkeys:

# Insecure vagrant SSH keys from https://github.com/mitchellh/vagrant/tree/master/keys
- 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key'

# Install key from your account just in case
- '{{ lookup("file","~/.ssh/id_rsa.pub") }}'

# Your own account
- name: '{{ lookup("env","USER") }}'
shell: '/bin/zsh'
dotfiles: True
groups: 'admins'
sshkeys:

# SSH key from your account
- '{{ lookup("file","~/.ssh/id_rsa.pub") }}'


53 changes: 53 additions & 0 deletions contrib/vagrant/inventory/host_vars/db.yml
@@ -0,0 +1,53 @@
---
# host: db

# MySQL server with PHPMyAdmin

# Enable PHPMyAdmin
mysql_phpmyadmin: True

# Default password for MySQL 'root' user
mysql_root_password: '{{ global_vagrant_password }}'

# MySQL should listen on all interfaces
# At the moment you might need to restart mysql-server on db for it to happen
# Command: ansible -s -i inventory-vagrant -m service -a 'name=mysql state=restarted' db
mysql_mysqld_bind_address: '0.0.0.0'

# Allow plaintext connections from local vagrant network
mysql_network_allow_list: [ '{{ global_vagrant_network }}' ]

# List of MySQL databases
mysql_databases:

# deploy
- name: '{{ global_vagrant_deploy }}'

# List of MySQL users
mysql_users:

# Your username, from localhost (db)
- name: '{{ lookup("env","USER") }}'
host: 'localhost'
priv: '*.*:ALL,GRANT'
password: '{{ global_vagrant_password }}'

# Your username, from local network
- name: '{{ lookup("env","USER") }}'
host: '192.168.50.%'
priv: '*.*:ALL,GRANT'
password: '{{ global_vagrant_password }}'

# deploy user, from localhost (db)
- name: '{{ global_vagrant_deploy }}'
host: 'localhost'
priv: '{{ global_vagrant_deploy }}.*:ALL'
password: '{{ global_vagrant_password }}'

# deploy user, from local network
- name: '{{ global_vagrant_deploy }}'
host: '192.168.50.%'
priv: '{{ global_vagrant_deploy }}.*:ALL'
password: '{{ global_vagrant_password }}'


9 changes: 9 additions & 0 deletions contrib/vagrant/inventory/host_vars/master.yml
@@ -0,0 +1,9 @@
---
# host: master

# Ansible Controller

# Install additional packages on this host
apt_host_packages: [ 'elinks', 'mutt' ]


37 changes: 37 additions & 0 deletions contrib/vagrant/inventory/host_vars/web.yml
@@ -0,0 +1,37 @@
---
# host: web

# LEMP webserver (Linux, nginx, MySQL, PHP5)

# Install additional PHP5 packages (it's good to add them in this variable
# instead of 'apt_*_packages', so that packages depending on php5 are installed
# after their dependencies)
php5_packages: [ 'php5-mysql' ]

# List of additional users configured on this host
users_host_list:

# Deploy user, with git access similar to Heroku cloud
- name: '{{ global_vagrant_deploy }}'
comment: 'Web Deployment'
type: 'git'
sshkeys:
- '{{ lookup("file","~/.ssh/id_rsa.pub") }}'

# List of nginx servers configured on this host
nginx_servers:
- '{{ nginx_default_server }}'

# Default nginx server with custom configuration
nginx_default_server:
enabled: True
default: True

# Enable userdir support, you can define one git repository as "userdir" and
# it will be available as http://hostname/~deploy/
# No PHP5 support though, just plain HTML/CSS
userdir: True
root: '/srv/users/{{ global_vagrant_deploy }}/sites/{{ ansible_hostname }}.{{ ansible_domain }}/public'
upstream_php5: 'php5_www-data'


25 changes: 25 additions & 0 deletions contrib/vagrant/inventory/hosts
@@ -0,0 +1,25 @@
# Default 'inventory/hosts' file for vagrant environment

# Host machine needs to be in the inventory for 'encfs' and 'secret' roles to
# work, otherwise it should be harmless
localhost ansible_connection=local

# Hosts defined in the Vagrantfile
[vagrant]
master ansible_ssh_host=192.168.50.2 ansible_ssh_user=vagrant ansible_ssh_private_key_file=contrib/vagrant/ssh/id_rsa_insecure
web ansible_ssh_host=192.168.50.10 ansible_ssh_user=vagrant ansible_ssh_private_key_file=contrib/vagrant/ssh/id_rsa_insecure
db ansible_ssh_host=192.168.50.20 ansible_ssh_user=vagrant ansible_ssh_private_key_file=contrib/vagrant/ssh/id_rsa_insecure

# Hosts with installed nginx webserver
[ginas_nginx]
web

# Hosts with installed PHP5
[ginas_php]
web

# Hosts with installed MySQL database
[ginas_mysql]
db


27 changes: 27 additions & 0 deletions contrib/vagrant/ssh/id_rsa_insecure
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKC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708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
+vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
-----END RSA PRIVATE KEY-----
1 change: 1 addition & 0 deletions inventory-vagrant
1 change: 1 addition & 0 deletions vagrant.sh

0 comments on commit e9203b4

Please sign in to comment.