-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
83 lines (71 loc) · 2.74 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- mode: ruby -*-
# vi: set ft=ruby :
required_plugins = %w(
vagrant-reload
vagrant-proxyconf
)
# Install required plugins
plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end
begin
require 'yaml'
PARAMS = YAML.load_file('config.yml')
PARAMS["vault_password_file"] = '/tmp/vault_pass'
PARAMS["vm"]["name"] = File.basename(__dir__)
rescue LoadError
puts "Configuration not found!"
puts "You must copy the 'config.yml.template' file as 'config.yml' and edit the values inside."
exit
end
Vagrant.configure("2") do |config|
class AnsibleVaultPassword
def to_s
print "Ansible vault password (leave empty if you're not using ansible-vault encrypted group variables): "
# temp hack to hide pwd characters input:
# - https://github.com/ruby/io-console/issues/2
# - https://github.com/hashicorp/vagrant/issues/5624#issuecomment-160473599
# 8m is the control code to hide characters
puts "\e[0;8m"
STDOUT.flush
stdin_pwd = STDIN.gets.chomp
# 0m is the control code to reset formatting attributes
puts "\e[0m"
STDOUT.flush
stdin_pwd.to_s.empty? ? 'no-password-provided' : stdin_pwd
end
end
config.vm.box = "fagia/ubuntu-elementary-de-16.04"
config.vm.box_version = "0.0.1"
config.vm.hostname = PARAMS["vm"]["name"]
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = PARAMS["vm"]["memory"]
vb.cpus = PARAMS["vm"]["cpus"]
vb.customize ["modifyvm", :id, "--vram", PARAMS["vm"]["vram"]]
vb.customize ["modifyvm", :id, "--clipboard", PARAMS["vm"]["clipboard"]]
vb.customize ["setextradata", :id, "GUI/MiniToolBarAlignment", "Top"]
end
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = PARAMS["proxy"]["http"]
config.proxy.https = PARAMS["proxy"]["https"]
config.proxy.no_proxy = PARAMS["proxy"]["no_proxy"]
end
config.vm.provision "shell", env: {"AVPWD" => AnsibleVaultPassword.new, "AVPASSFILE" => PARAMS["vault_password_file"]}, inline: "echo $AVPWD > $AVPASSFILE"
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "playbook.yml"
ansible.install_mode = "pip"
ansible.provisioning_path = "/vagrant/ansible"
ansible.vault_password_file = PARAMS["vault_password_file"]
ansible.extra_vars = { vault_password_file: PARAMS["vault_password_file"] }
ansible.limit = "localhost"
ansible.inventory_path = "inventory"
end
config.vm.provision :reload
end