From fe13be832b1f3e242cda6156aa1321fcdee457ca Mon Sep 17 00:00:00 2001 From: Sachin Prabhu Date: Wed, 17 Feb 2021 15:16:44 +0000 Subject: Generate Vagrantfile Convert the Vagrantfile to a jinja template. This allows us to specify which image to use by the vagrant executable. Signed-off-by: Sachin Prabhu --- vagrant/Vagrantfile | 97 ------------------------------ vagrant/local.yml | 1 + vagrant/roles/local.vagrant/tasks/main.yml | 5 ++ vagrant/templates/Vagrantfile.j2 | 97 ++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 97 deletions(-) delete mode 100644 vagrant/Vagrantfile create mode 100644 vagrant/templates/Vagrantfile.j2 (limited to 'vagrant') diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile deleted file mode 100644 index 519e7a3..0000000 --- a/vagrant/Vagrantfile +++ /dev/null @@ -1,97 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : -# - -NODES = 2 -DISKS = 3 -NODE_RAM = 1024 -NODE_CPUS = 2 -PRIVATE_NETWORK_BASE = "192.168.122" -PUBLIC_NETWORK_BASE = "192.168.123" -#LIBVIRT_STORAGE_POOL = "data" - -SETUP_IP = "#{PRIVATE_NETWORK_BASE}.200" -CLIENT_IP = "#{PUBLIC_NETWORK_BASE}.5" - -Vagrant.configure("2") do |config| - config.ssh.insert_key = false - config.vm.provider :libvirt do |v,override| - override.vm.box = "centos/7" - override.vm.synced_folder '.', '/vagrant', disabled: true - - # We can not use qemu_use_session universally. - # - On Fedora 31, it is required for me to start. - # - But on centos7, it must not be set. - # The best workarount I found is to put this setting into - # your ~/.vagrant.d/Vagrantfile like so: - # ``` - # Vagrant.configure("2") do |config| - # config.vm.provider :libvirt do |libvirt| - # libvirt.qemu_use_session = false - # end - # end - # ``` - #v.qemu_use_session = false - - # change cpu mode to passthrough as workaround for problems in the ci, - # refer to bugs: - # https://bugzilla.redhat.com/show_bug.cgi?id=1467599 - # https://bugzilla.redhat.com/show_bug.cgi?id=1386223#c10 - # vagrant-libvirt/vagrant-libvirt#667 - # taken from: - # https://github.com/heketi/heketi/pull/1008 - v.cpu_mode = 'host-passthrough' - end - - (0..NODES-1).each do |i| - config.vm.define "storage#{i}" do |storage| - storage.vm.hostname = "storage#{i}" - storage.vm.network :private_network, ip: "#{PRIVATE_NETWORK_BASE}.10#{i}" - storage.vm.network :private_network, ip: "#{PUBLIC_NETWORK_BASE}.10#{i}" - (0..DISKS-1).each do |d| - storage.vm.provider :virtualbox do |vb| - vb.customize [ "createhd", "--filename", "disk-#{i}#{d}.vdi", "--size", 10*1024 ] - vb.customize [ "storageattach", :id, "--storagectl", "SATA Controller", "--port", 3+d, "--device", 0, "--type", "hdd", "--medium", "disk-#{i}#{d}.vdi" ] - vb.memory = NODE_RAM - vb.cpus = NODE_CPUS - end - - driverletters = ('b'..'z').to_a - storage.vm.provider :libvirt do |lv| - if defined?(LIBVIRT_STORAGE_POOL) - lv.storage_pool_name = "#{LIBVIRT_STORAGE_POOL}" - end - lv.storage :file, :device => "vd#{driverletters[d]}", :path => "disk-#{i}#{d}.disk", :size => '10G' - lv.memory = NODE_RAM - lv.cpus = NODE_CPUS - end - end - end - end - - - # Client vm: - # This VM will connect to the cluster over the public ip addresses - config.vm.define "client1" do |setup| - setup.vm.hostname = "client1" - setup.vm.network :private_network, ip: "#{CLIENT_IP}" - end - - # setup vm: - # We will runn all our setup playbooks from there. - config.vm.define "setup" do |setup| - setup.vm.hostname = "setup" - setup.vm.network :private_network, ip: "#{SETUP_IP}" - # Run a no-op playbook to create the inventory file. - # Based on that, one can run ansible without vagrant. - setup.vm.provision "no-op", type:'ansible' do |ansible| - ansible.playbook = "no-op-playbook.yml" - ansible.groups = { - "admin" => [ "setup" ], - "clients" => [ "client1" ], - "cluster" => (0..NODES-1).map { |i| "storage#{i}" } - } - end - end - -end diff --git a/vagrant/local.yml b/vagrant/local.yml index e647c06..c46c922 100644 --- a/vagrant/local.yml +++ b/vagrant/local.yml @@ -2,5 +2,6 @@ connection: local become: no roles: + - local.defaults - local.vagrant - local.prep diff --git a/vagrant/roles/local.vagrant/tasks/main.yml b/vagrant/roles/local.vagrant/tasks/main.yml index 1d6c3b8..2f5b570 100644 --- a/vagrant/roles/local.vagrant/tasks/main.yml +++ b/vagrant/roles/local.vagrant/tasks/main.yml @@ -1,3 +1,8 @@ +- name: Setup Vagrant file + template: + src: Vagrantfile.j2 + dest: Vagrantfile + - name: start vagrant vms command: vagrant up --no-provision diff --git a/vagrant/templates/Vagrantfile.j2 b/vagrant/templates/Vagrantfile.j2 new file mode 100644 index 0000000..1ef3a53 --- /dev/null +++ b/vagrant/templates/Vagrantfile.j2 @@ -0,0 +1,97 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +# + +NODES = 2 +DISKS = 3 +NODE_RAM = 1024 +NODE_CPUS = 2 +PRIVATE_NETWORK_BASE = "192.168.122" +PUBLIC_NETWORK_BASE = "192.168.123" +#LIBVIRT_STORAGE_POOL = "data" + +SETUP_IP = "#{PRIVATE_NETWORK_BASE}.200" +CLIENT_IP = "#{PUBLIC_NETWORK_BASE}.5" + +Vagrant.configure("2") do |config| + config.ssh.insert_key = false + config.vm.provider :libvirt do |v,override| + override.vm.box = "{{ distro.vagrant_image }}" + override.vm.synced_folder '.', '/vagrant', disabled: true + + # We can not use qemu_use_session universally. + # - On Fedora 31, it is required for me to start. + # - But on centos7, it must not be set. + # The best workarount I found is to put this setting into + # your ~/.vagrant.d/Vagrantfile like so: + # ``` + # Vagrant.configure("2") do |config| + # config.vm.provider :libvirt do |libvirt| + # libvirt.qemu_use_session = false + # end + # end + # ``` + #v.qemu_use_session = false + + # change cpu mode to passthrough as workaround for problems in the ci, + # refer to bugs: + # https://bugzilla.redhat.com/show_bug.cgi?id=1467599 + # https://bugzilla.redhat.com/show_bug.cgi?id=1386223#c10 + # vagrant-libvirt/vagrant-libvirt#667 + # taken from: + # https://github.com/heketi/heketi/pull/1008 + v.cpu_mode = 'host-passthrough' + end + + (0..NODES-1).each do |i| + config.vm.define "storage#{i}" do |storage| + storage.vm.hostname = "storage#{i}" + storage.vm.network :private_network, ip: "#{PRIVATE_NETWORK_BASE}.10#{i}" + storage.vm.network :private_network, ip: "#{PUBLIC_NETWORK_BASE}.10#{i}" + (0..DISKS-1).each do |d| + storage.vm.provider :virtualbox do |vb| + vb.customize [ "createhd", "--filename", "disk-#{i}#{d}.vdi", "--size", 10*1024 ] + vb.customize [ "storageattach", :id, "--storagectl", "SATA Controller", "--port", 3+d, "--device", 0, "--type", "hdd", "--medium", "disk-#{i}#{d}.vdi" ] + vb.memory = NODE_RAM + vb.cpus = NODE_CPUS + end + + driverletters = ('b'..'z').to_a + storage.vm.provider :libvirt do |lv| + if defined?(LIBVIRT_STORAGE_POOL) + lv.storage_pool_name = "#{LIBVIRT_STORAGE_POOL}" + end + lv.storage :file, :device => "vd#{driverletters[d]}", :path => "disk-#{i}#{d}.disk", :size => '10G' + lv.memory = NODE_RAM + lv.cpus = NODE_CPUS + end + end + end + end + + + # Client vm: + # This VM will connect to the cluster over the public ip addresses + config.vm.define "client1" do |setup| + setup.vm.hostname = "client1" + setup.vm.network :private_network, ip: "#{CLIENT_IP}" + end + + # setup vm: + # We will runn all our setup playbooks from there. + config.vm.define "setup" do |setup| + setup.vm.hostname = "setup" + setup.vm.network :private_network, ip: "#{SETUP_IP}" + # Run a no-op playbook to create the inventory file. + # Based on that, one can run ansible without vagrant. + setup.vm.provision "no-op", type:'ansible' do |ansible| + ansible.playbook = "no-op-playbook.yml" + ansible.groups = { + "admin" => [ "setup" ], + "clients" => [ "client1" ], + "cluster" => (0..NODES-1).map { |i| "storage#{i}" } + } + end + end + +end -- cgit