1
0
Fork 0
ansible-install-server/Vagrantfile

81 lines
2.2 KiB
Ruby

# -*- mode: ruby -*-
# vi: set ft=ruby :
def create(config, name)
config.vm.define name do |v|
v.vm.hostname = name
v.vm.box = "generic/debian11"
v.vm.provider "virtualbox" do |vb|
vb.linked_clone = true
vb.cpus = 6
vb.memory = 2048
# special thing for virtualbox
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
end
v.vm.provider "libvirt" do |lv|
lv.cpus = 6
lv.memory = 2048
lv.disk_driver :cache => "unsafe"
end
# ADD EXTRA NIC FOR THE DHCP SERVICES
# https://github.com/vagrant-libvirt/vagrant-libvirt#provider-options
v.vm.network "private_network",
auto_config: false,
ip: '192.168.33.9',
netmask: '255.255.255.0',
virtualbox__intnet: true,
libvirt__dhcp_enabled: false,
libvirt__forward_mode: 'nat',
#libvirt__guest_ipv6: true,
#mode: 'isolated',
type: 'ethernet'
$provision_net = <<-EOF
ip a add 192.168.33.9/24 dev eth1
ip l set up dev eth1
EOF
v.vm.provision "shell", inline: $provision_net
if ENV['USE_ANSIBLE_IN_VM'] || false
# start vagrant with:
#
# USE_ANSIBLE_IN_VM=true vagrant up
#
# to provision the VM with ansible in the 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/vagrant.ini
cd /home/vagrant/fai
ansible-playbook -i ~/inventory/dezentrale.yml playbook-vagrant.yml
EOF
# and ran the provision with ansible
v.vm.provision "shell", inline: $provision
else
# provision with ansible and use VM as target host
v.vm.provision "ansible" do |ans|
ans.inventory_path = "inventory/dezentrale.yml"
ans.limit = name
#ans.ask_become_pass = true
ans.verbose = "v"
ans.playbook = "fai.yml"
#ans.tags = [ "debug_hostvars", "packages" ]
end
end
end
end
Vagrant.configure("2") do |config|
create(config, "hw4f-fai-vagrant")
end