Last active
June 12, 2016 15:08
-
-
Save Hounddog/52658bf77ecb87cfa41f to your computer and use it in GitHub Desktop.
Vagrant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - namespace: development | |
| provider: "virtualbox" | |
| box: ubuntu/trusty64 | |
| network: 192.168.123.0/24 | |
| count: 2 | |
| virtualbox: | |
| memory: 512 | |
| cpus: 1 | |
| ansible: | |
| playbook: ansible/development.yml | |
| group: development | |
| skip_tags: release | |
| - namespace: staging-release-1 | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-1825887d | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-f0b11187 | |
| elastic_ip: xx.xx.xx.xx | |
| associate_public_ip: false | |
| environment: "Staging" | |
| ansible: | |
| playbook: ansible/staging.yml | |
| group: staging-release | |
| skip_tags: phpunit | |
| vault_password_file: vault_pass.txt | |
| sync: | |
| disabled: true | |
| - namespace: staging-development | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-1825887d | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-f0b11187 | |
| elastic_ip: xx.xx.xx.xx | |
| associate_public_ip: false | |
| environment: "Staging" | |
| ansible: | |
| playbook: ansible/staging.yml | |
| group: staging-development | |
| skip_tags: phpunit | |
| vault_password_file: vault_pass.txt | |
| sync: | |
| disabled: true | |
| - namespace: qa-staging | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-1825887d | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-f19d0586 | |
| associate_public_ip: true | |
| elastic_ip: false | |
| ansible: | |
| playbook: ansible/testing.yml | |
| group: test | |
| skip_tags: release | |
| sync: | |
| disabled: false | |
| - namespace: qa-development | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-1825887d | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-f19d0586 | |
| associate_public_ip: true | |
| elastic_ip: false | |
| ansible: | |
| playbook: ansible/testing.yml | |
| group: test | |
| skip_tags: release | |
| sync: | |
| disabled: false | |
| - namespace: production-elastic | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-525ac637 | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-279c0450 | |
| private_ip: | |
| associate_public_ip: true | |
| elastic_ip: false | |
| security_groups: "sg-a21e58c7" | |
| environment: "Production" | |
| ansible: | |
| playbook: ansible/elasticsearch.yml | |
| group: production-elastic | |
| vault_password_file: vault_pass.txt | |
| sync: | |
| disabled: true | |
| - namespace: production-api | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-525ac637 | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-259c0452 | |
| associate_public_ip: true | |
| elastic_ip: false | |
| elb: "API" | |
| security_groups: "sg-a11056c4" | |
| environment: "Production" | |
| ansible: | |
| playbook: ansible/production-api.yml | |
| group: production-api | |
| skip_tags: phpunit | |
| vault_password_file: vault_pass.txt | |
| sync: | |
| disabled: true | |
| - namespace: production-prerender | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-525ac637 | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-b7bf27c0 | |
| private_ip: | |
| associate_public_ip: true | |
| elastic_ip: false | |
| security_groups: "sg-305c1a55" | |
| environment: "Production" | |
| ansible: | |
| playbook: ansible/prerender.yml | |
| group: production-prerender | |
| vault_password_file: vault_pass.txt | |
| sync: | |
| disabled: true | |
| - namespace: production-webserver | |
| provider: "aws" | |
| box: dummy | |
| box_url: https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box | |
| count: 1 | |
| aws: | |
| instance_type: t2.micro | |
| subnet_id: subnet-525ac637 | |
| region: eu-west-1 | |
| availability_zone: eu-west-1a | |
| ami: ami-c1bf27b6 | |
| private_ip: | |
| associate_public_ip: true | |
| elastic_ip: false | |
| security_groups: "sg-0b5c1a6e" | |
| environment: "Production" | |
| elb: "Website" | |
| ansible: | |
| playbook: ansible/production-webserver.yml | |
| group: production-webserver | |
| vault_password_file: vault_pass.txt | |
| sync: | |
| disabled: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- mode: ruby -*- | |
| # vi: set ft=ruby : | |
| require 'yaml' | |
| require 'ipaddr' | |
| settings = YAML.load_file 'vagrant.yml' | |
| aws_settings = settings["aws"] | |
| vm_settings = settings["vm"] | |
| # Read YAML file with box details | |
| servers = YAML.load_file('servers.yml') | |
| #ARGV | |
| skip = 0 | |
| while skip < ARGV.length | |
| if ARGV[skip].start_with?(arg='--vagrant-namespace=') | |
| v = ARGV.delete_at(skip).dup | |
| v.slice! arg | |
| namespacefilter = v.to_s # set namespace | |
| else # skip over "official" vagrant args | |
| skip = skip + 1 | |
| end | |
| end | |
| vms = [] | |
| ansible_groups = {}; | |
| #Assign Children groups for ansible | |
| ansible_groups['db:children'] = []; | |
| ansible_groups['db:children'] << 'development'; | |
| ansible_groups['elastic:children'] = []; | |
| ansible_groups['elastic:children'] << 'development'; | |
| ansible_groups['elastic:children'] << 'test'; | |
| ansible_groups['elastic:children'] << 'staging'; | |
| ansible_groups['elastic:children'] << 'production-elastic'; | |
| ansible_groups['api:children'] = []; | |
| ansible_groups['api:children'] << 'development'; | |
| ansible_groups['api:children'] << 'test'; | |
| ansible_groups['api:children'] << 'staging'; | |
| ansible_groups['api:children'] << 'production-api'; | |
| ansible_groups['staging:children'] = []; | |
| ansible_groups['staging:children'] << 'staging-release'; | |
| ansible_groups['staging:children'] << 'staging-development'; | |
| ansible_groups['webserver:children'] = []; | |
| ansible_groups['webserver:children'] << 'development'; | |
| ansible_groups['webserver:children'] << 'staging'; | |
| ansible_groups['webserver:children'] << 'production-webserver'; | |
| ansible_groups['prerender:children'] = []; | |
| ansible_groups['prerender:children'] << 'production-prerender'; | |
| ansible_groups['profiling:children'] = []; | |
| ansible_groups['profiling:children'] << 'development'; | |
| ansible_groups['profiling:children'] << 'staging'; | |
| ansible_groups['analytics:children'] = []; | |
| ansible_groups['analytics:children'] << 'development'; | |
| ansible_groups['analytics:children'] << 'staging'; | |
| servers.each do |servers, i| | |
| if servers['virtualbox'] != nil | |
| network_obj = IPAddr.new servers['network'] | |
| range = network_obj.to_range.to_a | |
| cidr = (32-(Math.log(range.length)/Math.log(2))).to_i | |
| offset = 100 # start hosts after here | |
| # remove reserved values | |
| range[0] = '__reserved_network_addr' # network | |
| range[1] = '__reserved_router_addr' # router (reserved) | |
| end | |
| #if namespacefilter != nil && namespacefilter != servers['namespace'] | |
| # next | |
| #end | |
| servers['name'] = servers['namespace'] | |
| count = servers['count'] | |
| (1..count).each do |i| | |
| h = "#{servers['namespace']}-#{i}" | |
| server = servers.dup | |
| server['name'] = h | |
| if servers['virtualbox'] != nil | |
| server['ip'] = range[offset+i].to_s | |
| end | |
| if ansible_groups.has_key?(servers["ansible"]["group"]) == false | |
| ansible_groups[servers["ansible"]["group"]] = []; | |
| end | |
| ansible_groups[servers["ansible"]["group"]] << server['name']; | |
| # generate names and add in the defaults | |
| vms.push(server) | |
| if namespacefilter == servers['namespace'] | |
| ARGV << h; | |
| end | |
| end | |
| end | |
| print ARGV; | |
| Vagrant.configure("2") do |config| | |
| vms.each do |vm| | |
| config.vm.define vm["name"] do |box| | |
| #ENV['VAGRANT_DEFAULT_PROVIDER'] = vm["provider"] | |
| box.vm.box = vm["box"] | |
| #Virtualbox Provider | |
| if vm['virtualbox'] != nil | |
| box.vm.network "private_network", ip: vm["ip"] | |
| box.vm.synced_folder "./", "/var/www/api.elephone.vb", :owner => "vagrant", :group => "www-data" | |
| box.vm.provider :virtualbox do |vb| | |
| vb.name = vm["name"] | |
| vb.customize [ | |
| "modifyvm", :id, | |
| "--memory", vm_settings["memory"], | |
| "--name", vm["name"], | |
| "--natdnshostresolver1", "on", | |
| "--cpus", vm_settings["cpus"], | |
| ] | |
| end | |
| end | |
| #Amazon Webservices Provider | |
| if vm['aws'] != nil | |
| box.vm.box_url = vm["box_url"] | |
| box.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ["src/vendor"], disabled: vm["sync"]["disabled"] | |
| box.vm.provider :aws do |aws, override| | |
| aws.access_key_id = aws_settings['access_key_id'] | |
| aws.secret_access_key = aws_settings['secret_access_key'] | |
| aws.keypair_name = aws_settings['keypair_name'] | |
| override.ssh.private_key_path = aws_settings['private_key_path'] | |
| aws.instance_type = vm["aws"]["instance_type"] | |
| aws.subnet_id = vm["aws"]["subnet_id"] | |
| aws.region = vm["aws"]["region"] | |
| aws.availability_zone = vm["aws"]["availability_zone"] | |
| aws.ami = vm["aws"]["ami"] | |
| override.ssh.username = "ubuntu" | |
| aws.elastic_ip = vm["aws"]["elastic_ip"] | |
| aws.associate_public_ip = vm["aws"]["associate_public_ip"] | |
| aws.tags = { | |
| "Name" => vm["name"], | |
| "Environment" => vm["aws"]['environment'] | |
| } | |
| if vm["aws"]["elb"] != nil | |
| aws.elb = vm["aws"]["elb"] | |
| end | |
| aws.security_groups = vm["aws"]["security_groups"] | |
| end | |
| end | |
| box.vm.provision :ansible do |ansible| | |
| ansible.playbook = vm["ansible"]["playbook"] | |
| ansible.limit = 'all' | |
| #ansible.verbose = 'vvvv' | |
| ansible.groups = ansible_groups; | |
| if vm["ansible"]["vault_password_file"] != nil | |
| ansible.vault_password_file = vm["ansible"]["vault_password_file"] | |
| end | |
| if vm["ansible"]["skip_tags"] != nil | |
| ansible.skip_tags = vm["ansible"]["skip_tags"] | |
| end | |
| ansible.vault_password_file="vault_pass.txt" | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment