Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: Vagrantfile

Issue 29367494: Issue 3065 - Introduce support for host-specific operating systems (Closed)
Patch Set: Created Dec. 14, 2016, 3:07 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | hiera/roles/default.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8
2 # vi: set fenc=utf-8 ft=ruby ts=8 sw=2 sts=2 et:
3 require 'shellwords'
1 require 'yaml' 4 require 'yaml'
2 5
3 VAGRANTFILE_API_VERSION = "2" 6 # https://issues.adblockplus.org/ticket/170
4 REPOSITORY_DIR = File.dirname(__FILE__) 7 if !system('python', File.expand_path('../ensure_dependencies.py', __FILE__))
5 DEPENDENCY_SCRIPT = File.join(REPOSITORY_DIR, "ensure_dependencies.py") 8 message = 'Failed to ensure dependencies being up-to-date!'
6 9 raise Vagrant::Errors::VagrantError, message
7 if !system("python", DEPENDENCY_SCRIPT)
8 error = Vagrant::Errors::VagrantError
9 error.error_message("Failed to ensure dependencies being up-to-date!")
10 raise error
11 end 10 end
12 11
13 def define_standard_vm(config, host_name, ip, role=nil) 12 # https://www.vagrantup.com/docs/vagrantfile/version.html
14 config.vm.define host_name do |config| 13 Vagrant.configure('2') do |config|
15 config.vm.box = 'precise64'
16 config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/precise/current/ precise-server-cloudimg-amd64-vagrant-disk1.box'
17 config.vm.host_name = "#{host_name}.adblockplus.org"
18 config.vm.network :private_network, ip: ip
19 config.vm.provider :virtualbox do |vb|
20 vb.customize ["modifyvm", :id, "--cpus", 1]
21 14
22 # Work around https://www.virtualbox.org/ticket/11649 15 # The repository location in the production system's puppet master
23 vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] 16 sync_path = '/etc/puppet/infrastructure'
17 sync_type = system('which', 'rsync', :out => File::NULL) ? 'rsync' : nil
24 18
25 setup_path = File.join(REPOSITORY_DIR, "hiera", "roles", "#{role}.yaml") 19 # See also modules/adblockplus/manifests/host.pp
26 setup = YAML.load_file(setup_path) rescue {} 20 hosts_file = File.expand_path('../modules/private/hiera/hosts.yaml', __FILE__)
27 requirements = setup.fetch("requirements", {}) 21 hosts_data = YAML.load_file(hosts_file)
22 hosts_data.fetch('adblockplus::hosts', {}).each_pair do |name, record|
28 23
29 requirements.each do |key, value| 24 # Formerly present hosts not destroyed yet require manual intervention
30 vb.customize ['modifyvm', :id, "--#{key}", "#{value}"] 25 next if record['ensure'] == 'absent'
26
27 # https://docs.puppet.com/puppet/latest/man/apply.html
28 puppet_options = Shellwords.split ENV.fetch('PUPPET_OPTIONS', '--verbose')
29 puppet_options << '--debug' unless ENV.fetch('PUPPET_DEBUG', '').empty?
30 puppet_options << '--environment=development'
31 puppet_options << "--external_nodes=#{sync_path}/hiera/puppet_node_classifie r.rb"
32 puppet_options << '--node_terminus=exec'
33
34 # https://www.vagrantup.com/docs/multi-machine/
35 config.vm.define name do |host|
36
37 if record.fetch('os', 'ubuntu-precise') == 'ubuntu-precise'
38
39 # http://cloud-images.ubuntu.com/vagrant/precise/current/
40 host.vm.box = 'precise64'
41 host.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/precise/curren t/precise-server-cloudimg-amd64-vagrant-disk1.box'
42
43 # https://www.vagrantup.com/docs/provisioning/shell.html
44 host.vm.provision :shell, :privileged => true, :inline => <<-end
45 python /etc/puppet/infrastructure/hiera/install_precise.py
46 end
47
48 # https://www.vagrantup.com/docs/synced-folders/
49 host.vm.synced_folder '.', sync_path, type: sync_type
50
51 elsif record['os'] == 'debian-jessie'
52
53 # https://www.vagrantup.com/docs/boxes.html
54 host.vm.box = 'debian/contrib-jessie64'
55 host.vm.box_url = 'https://atlas.hashicorp.com/debian/boxes/contrib-jess ie64'
56
57 # https://packages.debian.org/jessie/puppet
58 host.vm.provision :shell, :privileged => true, :inline => <<-end
59 set -e -- '#{sync_path}' /etc/puppet/hiera.yaml
60 if ! which puppet >/dev/null; then
61 apt-get -y update
62 apt-get -y install puppet
63 fi
64 test -e "$1" || ln -s /vagrant "$1"
65 test -e "$2" || ln -s infrastructure/hiera/hiera.yaml "$2"
66 puppet agent --enable
67 end
68
69 # https://docs.puppet.com/puppet/latest/configuration.html#hieraconfig
70 puppet_options << "--hiera_config=#{sync_path}/hiera/hiera.yaml"
71
72 else
73 message = "Unrecognized OS '#{record['os']}' for host '#{name}'"
74 raise Vagrant::Errors::VagrantError, message
31 end 75 end
32 76
77 # https://www.vagrantup.com/docs/vagrantfile/machine_settings.html
78 host.vm.hostname = record.fetch('fqdn', "#{name}.test")
79
80 # https://www.vagrantup.com/docs/networking/
81 host.vm.network :private_network, ip: record['ips'][0]
82
83 # https://www.vagrantup.com/docs/virtualbox/configuration.html
84 host.vm.provider :virtualbox do |virtualbox|
85
86 # The GUI would be just annoying to pop up by default every time
87 virtualbox.gui = !ENV.fetch('VIRTUALBOX_GUI', '').empty?
88
89 # Individual box configuration may increase the number of CPUs
90 virtualbox.customize ['modifyvm', :id, '--cpus', 1]
91 # Work around https://www.virtualbox.org/ticket/11649
92 virtualbox.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
93
94 # Role-specific requirements, optional
95 role_name = record.fetch('role', 'default')
96 role_file = File.expand_path("../hiera/roles/#{role_name}.yaml", __FILE_ _)
97 role_data = File.exists?(role_file) ? YAML.load_file(role_file) : {}
98 role_data.fetch('requirements', {}).each do |key, value|
99 virtualbox.customize ['modifyvm', :id, "--#{key}", value.to_s]
100 end
101
102 end
103
104 # https://www.vagrantup.com/docs/provisioning/puppet_apply.html
105 host.vm.provision :puppet do |puppet|
106 puppet.manifests_path = 'manifests'
107 puppet.manifest_file = 'site.pp'
108 puppet.module_path = 'modules'
109 puppet.options = puppet_options
110 end
111
112 # https://github.com/mitchellh/vagrant/issues/1673
113 host.ssh.shell = "sh -c 'BASH_ENV=/etc/profile exec bash'"
114
33 end 115 end
34 116
35 # The repository location in the production system's puppet master 117 end
36 if system('which', 'rsync', :out => File::NULL)
37 config.vm.synced_folder '.', '/etc/puppet/infrastructure', type: 'rsync'
38 else
39 config.vm.synced_folder '.', '/etc/puppet/infrastructure'
40 end
41 118
42 config.vm.provision :shell, :inline => '
43 sudo /etc/puppet/infrastructure/hiera/install_precise.py
44 '
45
46 config.vm.provision :puppet do |puppet|
47 puppet.options = [
48 '--environment=development',
49 '--external_nodes=/etc/puppet/infrastructure/hiera/puppet_node_classifie r.rb',
50 '--node_terminus=exec',
51 '--verbose',
52 '--debug',
53 ]
54 puppet.manifests_path = 'manifests'
55 puppet.manifest_file = 'site.pp'
56 puppet.module_path = 'modules'
57 end
58
59 yield(config) if block_given?
60 end
61 end 119 end
62
63 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
64 config_path = File.join(REPOSITORY_DIR, "modules/private/hiera/hosts.yaml")
65 config_data = YAML.load_file(config_path)
66 servers = config_data["adblockplus::hosts"]
67 servers.each do |server, items|
68 next if items['ensure'] == 'absent'
69 ip = items["ips"][0]
70 role = items.fetch("role", "default")
71 define_standard_vm(config, server, ip, role)
72 end
73 end
OLDNEW
« no previous file with comments | « no previous file | hiera/roles/default.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld