-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVagrantfile
More file actions
78 lines (60 loc) · 2.51 KB
/
Vagrantfile
File metadata and controls
78 lines (60 loc) · 2.51 KB
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
required_plugins = %w( vagrant-hostsupdater vagrant-host-shell )
required_plugins.each do |plugin|
system "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin
end
puts "Removing local SSH keys from known_hosts file..."
input_lines = File.readlines("#{Dir.home}/.ssh/known_hosts")
input_lines.delete_if {|x| x.include? "127.0.0.1"}
File.open("#{Dir.home}/.ssh/known_hosts", 'w') do |f|
input_lines.each do |line|
f.write line
end
end
# function to grab the hostname
def getHostName()
ENV['domain'] = ''
if File.file?('domain.txt')
ENV['domain'] = File.read('domain.txt')
end
if ENV['domain'] == ''
puts "Please enter a domain (it should follow the sitename.alphawerk.co.uk format!): "
ENV['domain'] = URI.escape(STDIN.gets.chomp)
File.open("domain.txt", "w") {|f| f.write(ENV['domain']) }
end
if ENV['domain'] == ''
getHostName()
else
if ENV['domain'] !~ /^(.+)\.alphawerk\.co\.uk$/
puts "Unconventional hostname format. sitename.alphawerk.co.uk format not followed"
end
puts "Setting up VM with domain: "+ENV['domain']
end
end
getHostName()
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.network :forwarded_port, guest: 443, host: 8443
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 3306, host: 3311
config.vm.network :private_network, ip: "127.0.0.1"
config.vm.hostname = ENV['domain']
config.vm.synced_folder ".", "/var/www/html/", id: "vagrant-root", type: "rsync", rsync__auto: true, rsync__exclude: ['./var*'],
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=777,fmode=777"]
config.vm.synced_folder ".ansible", "/vagrant", id: "ansible"
config.vm.provider :virtualbox do |vb|
vb.memory = 4096
vb.cpus = 3
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant-root", "1"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
config.vm.provision "shell", inline:
"sudo sed -i 's/nameserver.*/nameserver 1.1.1.1/' /etc/resolv.conf"
config.vm.provision "shell", inline:
"sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config && service sshd restart"
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "playbooks/master.yml"
ansible.extra_vars = { domain_input: ENV['domain'] }
end
end