aboutsummaryrefslogtreecommitdiffhomepage
path: root/Vagrantfile
blob: 9c68a3da4ed9e0cabe65e8b2acbbbfab5f7c2d93 (plain) (blame)
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
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  #Define if running desktop OS to yes otherwise no
  Desktop = "no"
  #Define the number of nodes to spin up
  N = 3

  #Iterate over nodes
  (1..N).each do |node_id|
    nid = (node_id - 1)

    config.vm.define "node#{nid}" do |node|
      node.vm.box = "mrlesmithjr/centos-7"
      node.vm.provider "virtualbox" do |vb|
        vb.memory = "1024"
        vb.cpus = "1"
        if Desktop == "yes"
          vb.gui = true
          vb.customize ["modifyvm", :id, "--graphicscontroller", "vboxvga"]
          vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
          vb.customize ["modifyvm", :id, "--ioapic", "on"]
          vb.customize ["modifyvm", :id, "--vram", "128"]
          vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
        end
      end
      node.vm.hostname = "node#{nid}"
      ### Define additional network adapters below
      node.vm.network :private_network, ip: "192.168.202.#{200 + nid}"

      ### Define port forwards below
#      node.vm.network "forwarded_port", guest: 80, host: "#{8080 + nid}"
#      node.vm.network "forwarded_port", guest: 3000, host: "#{3000 + nid}"

      if node_id == N
        node.vm.provision :shell, path: "bootstrap.sh", keep_color: "true"  #runs initial shell script
        node.vm.provision "ansible" do |ansible|  #runs bootstrap Ansible playbook
          ansible.limit = "all"
          ansible.playbook = "bootstrap.yml"
        end
        node.vm.provision "ansible" do |ansible|  #runs Ansible playbook for installing roles/executing tasks
          ansible.limit = "all"
          ansible.playbook = "playbook.yml"
          ansible.groups = {
            "test-nodes" => [
              "node0",
              "node1"
            ],
            "prod-nodes" => [
              "node2"
            ]
          }
        end
      end

    end
  end
end