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

Delta Between Two Patch Sets: Vagrantfile

Issue 4810150141493248: Issue 122 - Puppet ENC via Hiera (Closed)
Left Patch Set: 112 - Puppet ENC via Hiera Created Oct. 8, 2014, 3:02 a.m.
Right Patch Set: Puppet ENC via Hiera - Without Arrow Alignment Created March 16, 2015, 2:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « README.md ('k') | hiera/hiera.yaml » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 require 'yaml' 1 require 'yaml'
2 2
3 VAGRANTFILE_API_VERSION = "2" 3 VAGRANTFILE_API_VERSION = "2"
4 REPOSITORY_DIR = File.dirname(__FILE__) 4 REPOSITORY_DIR = File.dirname(__FILE__)
5 DEPENDENCY_SCRIPT = File.join(REPOSITORY_DIR, "ensure_dependencies.py") 5 DEPENDENCY_SCRIPT = File.join(REPOSITORY_DIR, "ensure_dependencies.py")
6 6
7 if !system("python", DEPENDENCY_SCRIPT) 7 if !system("python", DEPENDENCY_SCRIPT)
8 error = Vagrant::Errors::VagrantError 8 error = Vagrant::Errors::VagrantError
9 error.error_message("Failed to ensure dependencies being up-to-date!") 9 error.error_message("Failed to ensure dependencies being up-to-date!")
10 raise error 10 raise error
11 end 11 end
12 12
13 def define_standard_vm(config, host_name, ip, role=nil) 13 def define_standard_vm(config, host_name, ip, role=nil)
14 config.vm.define host_name do |config| 14 config.vm.define host_name do |config|
15
16 config.vm.box = 'precise64' 15 config.vm.box = 'precise64'
17 config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/precise/current/ precise-server-cloudimg-amd64-vagrant-disk1.box' 16 config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/precise/current/ precise-server-cloudimg-amd64-vagrant-disk1.box'
18 config.vm.host_name = "#{host_name}.adblockplus.org" 17 config.vm.host_name = "#{host_name}.adblockplus.org"
19 config.vm.network :private_network, ip: ip 18 config.vm.network :private_network, ip: ip
20 config.vm.provider :virtualbox do |vb| 19 config.vm.provider :virtualbox do |vb|
21
22 vb.customize ["modifyvm", :id, "--cpus", 1] 20 vb.customize ["modifyvm", :id, "--cpus", 1]
23 21
24 # Work around https://www.virtualbox.org/ticket/11649 22 # Work around https://www.virtualbox.org/ticket/11649
25 vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] 23 vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
26 24
27 if role == nil 25 setup_path = File.join(REPOSITORY_DIR, "hiera", "roles", "#{role}.yaml")
Wladimir Palant 2014/11/17 16:43:36 Can role ever be nil? I don't think we want to hav
mathias 2014/11/27 00:30:18 Agreed, we do not need a host being configured by
28 setup_path = File.join(Dir.pwd, "hiera", "hosts", "#{host_name}.yaml")
Wladimir Palant 2014/11/17 16:43:36 Please don't use Dir.pwd here or elsewhere, its va
mathias 2014/11/27 00:30:18 Done.
29 else
30 setup_path = File.join(Dir.pwd, "hiera", "roles", "#{role}.yaml")
31 end
32
33 setup = YAML.load_file(setup_path) rescue {} 26 setup = YAML.load_file(setup_path) rescue {}
34 requirements = setup.fetch("requirements", {}) 27 requirements = setup.fetch("requirements", {})
35 28
36 requirements.each do |key, value| 29 requirements.each do |key, value|
37 vb.customize ['modifyvm', :id, "--#{key}", "#{value}"] 30 vb.customize ['modifyvm', :id, "--#{key}", "#{value}"]
38 end 31 end
39 32
40 end 33 end
41 34
42 # The repository location in the production system's puppet master 35 # The repository location in the production system's puppet master
43 config.vm.synced_folder ".", "/etc/puppet/infrastructure" 36 config.vm.synced_folder ".", "/etc/puppet/infrastructure"
44 37
45 config.vm.provision :shell, :inline => ' 38 config.vm.provision :shell, :inline => '
46 sudo /etc/puppet/infrastructure/hiera/install-precise.py 39 sudo /etc/puppet/infrastructure/hiera/install_precise.py
47 ' 40 '
48 41
49 config.vm.provision :puppet do |puppet| 42 config.vm.provision :puppet do |puppet|
50 puppet.options = [ 43 puppet.options = [
51 '--environment=development', 44 '--environment=development',
52 '--external_nodes=/etc/puppet/infrastructure/hiera/puppet-node-classifie r.rb', 45 '--external_nodes=/etc/puppet/infrastructure/hiera/puppet_node_classifie r.rb',
53 '--node_terminus=exec', 46 '--node_terminus=exec',
54 '--verbose', 47 '--verbose',
55 '--debug', 48 '--debug',
Wladimir Palant 2014/11/17 16:43:36 Debug output isn't going to be too useful, right?
mathias 2014/11/27 00:30:18 It is super useful! It doesn't seem to make much s
56 ] 49 ]
57 puppet.manifests_path = 'manifests' 50 puppet.manifests_path = 'manifests'
58 puppet.manifest_file = 'nodes.pp' 51 puppet.manifest_file = 'nodes.pp'
59 puppet.module_path = 'modules' 52 puppet.module_path = 'modules'
60 # Requires Puppet 3.x or later
61 #puppet.hiera_config_path = 'hiera/vagrant.yaml'
62 end 53 end
63 54
64 yield(config) if block_given? 55 yield(config) if block_given?
65
66 end 56 end
67 end 57 end
68 58
69 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 59 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
70 configYAML = File.join(Dir.pwd, "hiera/environment/hosts.yaml") 60 config_path = File.join(REPOSITORY_DIR, "hiera/private/hosts.yaml")
71 configServers = YAML.load_file(configYAML) 61 config_data = YAML.load_file(config_path)
72 servers = configServers["servers"] 62 servers = config_data["servers"]
73 servers.each do |server, items| 63 servers.each do |server, items|
74 ip = items["ip"][0] 64 ip = items["ip"][0]
75 role = items.fetch("role", "default") 65 role = items.fetch("role", "default")
76 define_standard_vm(config, server, ip, role) 66 define_standard_vm(config, server, ip, role)
77 end 67 end
78 end 68 end
LEFTRIGHT

Powered by Google App Engine
This is Rietveld