55 lines
1.4 KiB
Ruby
55 lines
1.4 KiB
Ruby
# -*- mode: ruby -*-
|
|
# vi: set ft=ruby :
|
|
|
|
# start vagrant with:
|
|
#
|
|
# USE_ANSIBLE_IN_VM=true vagrant up
|
|
#
|
|
# to provision the VM with ansible in the VM
|
|
$use_ansible_in_vm = ENV['USE_ANSIBLE_IN_VM'] || false
|
|
|
|
def create(config, name)
|
|
config.vm.define name do |v|
|
|
v.vm.hostname = name
|
|
v.vm.box = "generic/debian10"
|
|
|
|
v.vm.provider "virtualbox" do |vb|
|
|
vb.linked_clone = true
|
|
vb.cpus = 2
|
|
vb.memory = 1024
|
|
# special thing for virtualbox
|
|
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
|
|
end
|
|
|
|
# add a extra NIC for the DHCP services
|
|
v.vm.network "private_network", virtualbox__intnet: true, auto_config: false
|
|
|
|
if $use_ansible_in_vm
|
|
# copy the project to vagrant user
|
|
v.vm.synced_folder ".", "/home/vagrant/fai", type: "rsync"
|
|
|
|
$provision = <<-EOF
|
|
sudo apt-get install -y python3-pip
|
|
pip3 install ansible
|
|
echo faiserver ansible_connection=local python_interpreter=/usr/bin/python3 > ~/inventory
|
|
cd /home/vagrant/fai
|
|
ansible-playbook -i ~/inventory playbook-vagrant.yml
|
|
EOF
|
|
|
|
# and ran the provision with ansible
|
|
v.vm.provision "shell", inline: $provision
|
|
|
|
else
|
|
# ran provision with ansible and use VM as target host
|
|
v.vm.provision "ansible" do |ans|
|
|
ans.playbook = "playbook-vagrant.yml"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
Vagrant.configure("2") do |config|
|
|
create(config, "faiserver")
|
|
end
|
|
|