This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VagrantFile
67 lines (57 loc) · 3.31 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
# Read YAML file with box details
serversYaml = YAML.load_file('./deploy/infra_local.yml')
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.ssh.insert_key = false
config.vm.provider "virtualbox" do |virtualbox|
virtualbox.memory = 2048
virtualbox.cpus = 4
end
# Setup whole infra
serversYaml.each do |server|
servername = server["name"]
config.vm.define servername do |serverconfig|
serverconfig.vm.hostname = servername
serverconfig.vm.network "private_network", ip: server["ip"]
serverconfig.vm.provider "virtualbox" do |virtualbox|
virtualbox.name = servername
end
serverconfig.vm.provision "file", source: "./keys_local/LocalAnsibleKey.key", destination: "/tmp/private_key"
serverconfig.vm.provision :shell, :inline => "useradd ansible"
serverconfig.vm.provision :shell, :inline => "mkdir /home/ansible"
serverconfig.vm.provision :shell, :inline => "mkdir /home/ansible/.ssh"
serverconfig.vm.provision :shell, :inline => "ssh-keygen -y -f /tmp/private_key > /home/ansible/.ssh/authorized_keys"
serverconfig.vm.provision :shell, :inline => "chmod u=rx,go= /home/ansible/.ssh"
serverconfig.vm.provision :shell, :inline => "chmod u=r,go= /home/ansible/.ssh/authorized_keys"
serverconfig.vm.provision :shell, :inline => "chown -R ansible:ansible /home/ansible"
serverconfig.vm.provision :shell, :inline => "rm /tmp/private_key"
serverconfig.vm.provision :shell, :inline => "echo 'ansible ALL=(ALL) NOPASSWD:ALL'> /etc/sudoers.d/ansible"
serverconfig.vm.provision :shell, :inline => "chmod ug=r,o= /etc/sudoers.d/ansible"
serverconfig.vm.provision :shell, :inline => "chown -R root:root /etc/sudoers.d/ansible"
end
end
config.vm.define "deploy" do |deploy|
deploy.vm.hostname = "deploy"
deploy.vm.network "private_network", ip: "192.168.50.100"
deploy.vm.provider "virtualbox" do |virtualbox|
virtualbox.name = "deploy"
end
# Shared folders
deploy.vm.synced_folder "./deploy", "/home/vagrant/deploy"
deploy.vm.synced_folder "./src", "/home/vagrant/src"
deploy.vm.synced_folder "./keys_local", "/home/vagrant/keys_local", mount_options: ["dmode=700","fmode=600"]
# Setup
deploy.vm.provision :shell, :inline => "apt-add-repository ppa:ansible/ansible"
deploy.vm.provision :shell, :inline => "apt-get update"
deploy.vm.provision :shell, :inline => "apt-get -y install ansible"
deploy.vm.provision :shell, :inline => "apt-get -y install python"
deploy.vm.provision :shell, :inline => "ansible-playbook deploy/playbook_ansible_config.yml --connection=local"
deploy.vm.provision :shell, :inline => "history -s ansible-playbook deploy/playbook.yml --inventory-file=deploy/infra.py --tags=deploy"
deploy.vm.provision :shell, :inline => "history -s ansible-playbook deploy/playbook.yml --inventory-file=deploy/infra.py"
end
end