From b7a43229c0caeee27cb75367d0dd471da3f3e5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20B=C3=B6hm?= Date: Sat, 20 Mar 2021 18:17:49 +0100 Subject: [PATCH] Some customization for vagrant --- Vagrantfile | 36 +++++++++++++++++++++++++++++++++--- playbook-vagrant.yml | 1 - 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 59af0bb..7de8e6b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,20 +1,49 @@ # -*- 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.memory = "1024" + 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 - v.vm.provision "ansible" do |ans| - ans.playbook = "playbook-vagrant.yml" + 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 @@ -22,3 +51,4 @@ end Vagrant.configure("2") do |config| create(config, "faiserver") end + diff --git a/playbook-vagrant.yml b/playbook-vagrant.yml index 0381ddb..ebcdab3 100644 --- a/playbook-vagrant.yml +++ b/playbook-vagrant.yml @@ -33,4 +33,3 @@ roles: - fai -