# -*- mode: ruby -*- # -*- coding: utf-8 -*- host_folder_ansible = "../ansible" synced_folder_ansible = "/ansible" synced_folder_main = "/vagrant" synced_folder_config = "#{synced_folder_main}/config" os_config = "#{synced_folder_config}/local.conf" os_clouds_template = "#{synced_folder_config}/clouds.yaml" os_clouds_dir = "${HOME}/.config/openstack" os_clouds_config = "#{os_clouds_dir}/clouds.yaml" os_admin = "admin" os_user = "demo" vm_cpu = 1 vm_cpus = 4 vm_memory = 1 * 1024 vm_memory_os = 8 * 1024 vm_disk = 32 vm_box = "generic/ubuntu1804" operation = { name: 'operator', hostname: 'operator', ip: '172.17.5.254', ip_os: '172.24.4.254', cpus: vm_cpu, memory: vm_memory, disk: vm_disk } devstack = { name: 'devstack', hostname: 'devstack', ip: '172.17.5.200', ip_os: '172.24.4.2', cpus: vm_cpus, memory: vm_memory_os, disk: vm_disk } all = [] << operation << devstack operation_post_msg = "Run: \"vagrant provision #{operation[:name]} --provision-with=run_playbook_create\" to complete infrastructure deployment" $enable_ipv6 = <<-SCRIPT sed -i'' 's/net.ipv6.conf.all.disable_ipv6.*$/net.ipv6.conf.all.disable_ipv6 = 0/' /etc/sysctl.conf sysctl -p SCRIPT $setup_devstack = <<-SCRIPT CONFIG="$1" git clone https://opendev.org/openstack/devstack cd devstack cp "$CONFIG" . ./stack.sh SCRIPT $setup_py = <<-SCRIPT export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install -yq python3-distutils curl -fsSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py SCRIPT $setup_openstackclient = <<-SCRIPT pip install --ignore-installed python-openstackclient mkdir -p #{os_clouds_dir} SCRIPT $setup_openstacksdk = <<-SCRIPT pip install ansible openstacksdk mkdir -p #{os_clouds_dir} SCRIPT $create_os_clouds = <<-SCRIPT user="$1" template="$2" config="$3" OS_USERNAME="$user" envsubst < "$template" > "$config" SCRIPT $run_playbook = <<-SCRIPT PLAYBOOK="$1" export OS_CLOUD=openstack cd #{synced_folder_ansible} ansible-playbook "$PLAYBOOK" SCRIPT Vagrant.configure("2") do |config| all.each do |machine| config.vm.define machine[:name] do |config| config.vm.box = vm_box config.vm.hostname = machine[:hostname] config.vm.provider :virtualbox do |v| v.name = machine[:name] v.memory = machine[:memory] v.cpus = machine[:cpus] end config.vm.provider :libvirt do |v| v.memory = machine[:memory] v.cpus = machine[:cpus] v.machine_virtual_size = machine[:disk] # set at VM creation end config.vm.network :private_network, ip: machine[:ip] config.vm.network :private_network, ip: machine[:ip_os] if machine[:name] == 'devstack' config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: "Vagrantfile" config.vm.provision "enable_ipv6", type: :shell, run: "always", inline: $enable_ipv6 config.vm.provision "setup_devstack", type: :shell, privileged: false, inline: $setup_devstack, args: os_config end if machine[:name] == 'operator' config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: "Vagrantfile" config.vm.synced_folder host_folder_ansible, synced_folder_ansible, type: "rsync" config.vm.provision "setup_py", type: :shell, inline: $setup_py config.vm.provision "setup_openstackclient", type: :shell, inline: $setup_openstackclient config.vm.provision "create_os_clouds_admin", type: :shell, run: "always" do |s| s.inline = $create_os_clouds s.args = [os_admin, os_clouds_template, os_clouds_config] end config.vm.provision "setup_openstacksdk", type: :shell, privileged: false, inline: $setup_openstacksdk config.vm.provision "create_os_clouds", type: :shell, run: "always" do |s| s.privileged = false s.inline = $create_os_clouds s.args = [os_user, os_clouds_template, os_clouds_config] end config.vm.post_up_message = operation_post_msg config.vm.provision "run_playbook_create", type: :shell, run: "never" do |s| s.privileged = false s.inline = $run_playbook s.args = "create.yml" end config.vm.provision "run_playbook_destroy", type: :shell, run: "never" do |s| s.privileged = false s.inline = $run_playbook s.args = "destroy.yml" end end end end end