# -*- mode: ruby -*-
# vi: set ft=ruby :

# README
#
# Getting Started:
# 1. vagrant plugin install vagrant-hostmanager
# 2. vagrant up
# 3. vagrant ssh
#
# This should put you at the dev host
#  with access, by name, to other vms


Vagrant.configure("2") do |config|
  config.hostmanager.enabled = true
  #
  # This version does not include VB Guest additions which are needed for shared folders
  # This also typically sets the synced folder type to rsync, which means it won't sync changes after the initial boot
  #
  #config.vm.box = "centos/7"
  #
  #
  #
  #config.vm.box = "ubuntu/trusty64"
  #
  # CentOS 7.x and Vagrant 1.91 has an issue with Vagrant defined private network
  # https://github.com/mitchellh/vagrant/issues/8096
  # https://github.com/mitchellh/vagrant/issues/8115
  #
  #
  # Using VB
  # Using geerlingguy/centos7
  #
  config.vm.box = "geerlingguy/centos7"


  #
  # all machine names should match what is in the inventory

  #
  # dev machine
  #
  # make it primary thus a vagrant ssh will default to it
  #
  config.vm.define "dev", primary: true do |h|
    h.vm.hostname = "dev"
    h.vm.network "private_network", ip: "192.168.100.20"
    #
    # angular2 dev defaults to port 4200 so use that one
    #
    h.vm.network "forwarded_port", guest: 4200, host: 4200
    #
    # Due to network manager bug (https://github.com/mitchellh/vagrant/issues/8096), always restart the network interface when bringing up the VM
    #
    h.vm.provision :shell, :inline => "sudo service network restart", :run => 'always'
    #
    # install yum-utils to get basic yum tools to allow other items to be installed
    #
    h.vm.provision :shell, :inline => "sudo yum -y install yum-utils"
    #
    # install the MCCF VA baseline for a dev machine
    # the systemd downgrade is a temporary workaround. CM and SAs are working the problem - 29 Mar 2017
    #
    h.vm.provision :shell, :inline => <<'EOF'
sudo yum downgrade systemd-219-30.el7_3.7 --disablerepo="*" --enablerepo=mccf-va --enablerepo=mccf
sudo yum-config-manager -y --add-repo http://34.195.104.160/dev/repo/yum/mccf-dev.repo
sudo yum -y groupinstall "MCCF VA Base" --disablerepo="*" --enablerepo=mccf-va --enablerepo=mccf --skip-broken
EOF
    #
    # install git as it will be required to download ansible roles
    #
    h.vm.provision :shell, :inline => "sudo yum -y install git"
    #
    # install ansible
    #
    h.vm.provision :shell, :inline => "sudo yum -y install ansible"
    #
    # install certs to allow ssh'ing between machines
    #
    h.vm.provision :shell, :inline => <<'EOF'
if [ ! -f "/home/vagrant/.ssh/id_rsa" ]; then
  ssh-keygen -t rsa -N "" -f /home/vagrant/.ssh/id_rsa
fi
cp /home/vagrant/.ssh/id_rsa.pub /vagrant/control.pub

cat << 'SSHEOF' > /home/vagrant/.ssh/config
Host *
  StrictHostKeyChecking no
  UserKnownHostsFile=/dev/null
SSHEOF

chown -R vagrant:vagrant /home/vagrant/.ssh/
EOF
  end

end
