From 8fcff30122877fde2a5cb9507451376cd5208290 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 4 Apr 2023 08:51:02 +0200 Subject: [PATCH] Initial import --- .gitignore | 4 + vagrant--devstack/Makefile | 4 + vagrant--devstack/README.md | 5 ++ vagrant--devstack/Vagrantfile | 36 ++++++++ vagrant--devstack/provision/base.sh | 15 ++++ vagrant--devstack/provision/openstack.sh | 37 ++++++++ vagrant--kolla-ansible/Makefile | 4 + vagrant--kolla-ansible/README.md | 5 ++ vagrant--kolla-ansible/Vagrantfile | 36 ++++++++ vagrant--kolla-ansible/provision/base.sh | 15 ++++ .../provision/openstack-kolla.sh | 87 +++++++++++++++++++ 11 files changed, 248 insertions(+) create mode 100644 .gitignore create mode 100644 vagrant--devstack/Makefile create mode 100644 vagrant--devstack/README.md create mode 100644 vagrant--devstack/Vagrantfile create mode 100755 vagrant--devstack/provision/base.sh create mode 100755 vagrant--devstack/provision/openstack.sh create mode 100644 vagrant--kolla-ansible/Makefile create mode 100644 vagrant--kolla-ansible/README.md create mode 100644 vagrant--kolla-ansible/Vagrantfile create mode 100755 vagrant--kolla-ansible/provision/base.sh create mode 100755 vagrant--kolla-ansible/provision/openstack-kolla.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..08b854e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vagrant +/slides/autoslide.md +tmp +/_* diff --git a/vagrant--devstack/Makefile b/vagrant--devstack/Makefile new file mode 100644 index 0000000..a593fe4 --- /dev/null +++ b/vagrant--devstack/Makefile @@ -0,0 +1,4 @@ + +zip: + zip -r kubernetes--lab.zip Vagrantfile provision.sh + diff --git a/vagrant--devstack/README.md b/vagrant--devstack/README.md new file mode 100644 index 0000000..3c725d6 --- /dev/null +++ b/vagrant--devstack/README.md @@ -0,0 +1,5 @@ + + +# Other + +* https://opendev.org/openstack/devstack-vagrant diff --git a/vagrant--devstack/Vagrantfile b/vagrant--devstack/Vagrantfile new file mode 100644 index 0000000..2884124 --- /dev/null +++ b/vagrant--devstack/Vagrantfile @@ -0,0 +1,36 @@ +# vim: set ts=2 sw=2 et ft=ruby: +# frozen_string_literal: true + +Vagrant.configure('2') do |config| + config.vm.box = 'debian/bullseye64' + + config.vm.provider 'libvirt' do |domain| + domain.memory = 18_000 + domain.nested = true + domain.cpus = 2 + end + + config.vm.provider 'virtualbox' do |vb| + vb.gui = false + vb.memory = 18_000.to_s + # vb.nested = true + vb.customize ['modifyvm', :id, '--nested-hw-virt', 'on'] + end + + # config.vm.synced_folder "..", "/vagrant" #, type: "nfs", mount_options: ['actimeo=2'] + # config.vm.synced_folder "../../exercises", "/vagrant/exercises" #, type: "nfs", mount_options: ['actimeo=2'] + # config.vm.synced_folder "../../config", "/vagrant/config" #, type: "nfs", mount_options: ['actimeo=2'] + + config.vm.define 'control' do |machine| + machine.vm.hostname = 'control' + + [3000, 4000, 5000, 8000, 8080].each do |port| + machine.vm.network 'forwarded_port', guest: port, host: port, host_ip: '127.0.0.1' + end + machine.vm.network 'forwarded_port', guest: 80, host: 1080, host_ip: '127.0.0.1' + end + + config.vm.provision 'shell', name: 'provision/base', path: 'provision/base.sh', privileged: true + config.vm.provision 'shell', name: 'provision/openstack', path: 'provision/openstack.sh', privileged: false + config.vm.provision 'shell', inline: 'echo "SUCCESS"' +end diff --git a/vagrant--devstack/provision/base.sh b/vagrant--devstack/provision/base.sh new file mode 100755 index 0000000..ff8bea1 --- /dev/null +++ b/vagrant--devstack/provision/base.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +echo "Installing required system packages" +apt-get update -qq --allow-releaseinfo-change +apt-get install -qq -y \ + apt-transport-https \ + ca-certificates \ + git \ + curl \ + wget \ + vim \ + gnupg2 \ + fzf \ + software-properties-common + diff --git a/vagrant--devstack/provision/openstack.sh b/vagrant--devstack/provision/openstack.sh new file mode 100755 index 0000000..5ad090e --- /dev/null +++ b/vagrant--devstack/provision/openstack.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# useradd -s /bin/bash -d /opt/stack -m stack +# chmod +x /opt/stack + +# apt-get install sudo -y +# echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack + +## +## Install prerequisites +## +sudo apt-get install -y git + +## +## Get openstack +## +git clone https://opendev.org/openstack/devstack +cd devstack || exit 1 + +## +## Create configuration +## +cat > local.conf <<-MARK +[[local|localrc]] +FLOATING_RANGE=192.168.1.224/27 +FIXED_RANGE=10.11.12.0/24 +ADMIN_PASSWORD=admin1pass +DATABASE_PASSWORD=database2pass +RABBIT_PASSWORD=rabbit3pass +SERVICE_PASSWORD=service4pass +MARK + +## +## Run devstack +## +./stack.sh + diff --git a/vagrant--kolla-ansible/Makefile b/vagrant--kolla-ansible/Makefile new file mode 100644 index 0000000..a593fe4 --- /dev/null +++ b/vagrant--kolla-ansible/Makefile @@ -0,0 +1,4 @@ + +zip: + zip -r kubernetes--lab.zip Vagrantfile provision.sh + diff --git a/vagrant--kolla-ansible/README.md b/vagrant--kolla-ansible/README.md new file mode 100644 index 0000000..3c725d6 --- /dev/null +++ b/vagrant--kolla-ansible/README.md @@ -0,0 +1,5 @@ + + +# Other + +* https://opendev.org/openstack/devstack-vagrant diff --git a/vagrant--kolla-ansible/Vagrantfile b/vagrant--kolla-ansible/Vagrantfile new file mode 100644 index 0000000..1e5b59c --- /dev/null +++ b/vagrant--kolla-ansible/Vagrantfile @@ -0,0 +1,36 @@ +# vim: set ts=2 sw=2 et ft=ruby: +# frozen_string_literal: true + +Vagrant.configure('2') do |config| + config.vm.box = 'debian/bullseye64' + + config.vm.provider 'libvirt' do |domain| + domain.memory = 18_000 + domain.nested = true + domain.cpus = 2 + end + + config.vm.provider 'virtualbox' do |vb| + vb.gui = false + vb.memory = 18_000.to_s + # vb.nested = true + vb.customize ['modifyvm', :id, '--nested-hw-virt', 'on'] + end + + # config.vm.synced_folder "..", "/vagrant" #, type: "nfs", mount_options: ['actimeo=2'] + # config.vm.synced_folder "../../exercises", "/vagrant/exercises" #, type: "nfs", mount_options: ['actimeo=2'] + # config.vm.synced_folder "../../config", "/vagrant/config" #, type: "nfs", mount_options: ['actimeo=2'] + + config.vm.define 'control' do |machine| + machine.vm.hostname = 'control' + + [3000, 4000, 5000, 8000, 8080].each do |port| + machine.vm.network 'forwarded_port', guest: port, host: port, host_ip: '127.0.0.1' + end + machine.vm.network 'forwarded_port', guest: 80, host: 1080, host_ip: '127.0.0.1' + end + + config.vm.provision 'shell', name: 'provision/base', path: 'provision/base.sh', privileged: true + config.vm.provision 'shell', name: 'provision/openstack-kolla', path: 'provision/openstack-kolla.sh', privileged: false + config.vm.provision 'shell', inline: 'echo "SUCCESS"' +end diff --git a/vagrant--kolla-ansible/provision/base.sh b/vagrant--kolla-ansible/provision/base.sh new file mode 100755 index 0000000..ff8bea1 --- /dev/null +++ b/vagrant--kolla-ansible/provision/base.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +echo "Installing required system packages" +apt-get update -qq --allow-releaseinfo-change +apt-get install -qq -y \ + apt-transport-https \ + ca-certificates \ + git \ + curl \ + wget \ + vim \ + gnupg2 \ + fzf \ + software-properties-common + diff --git a/vagrant--kolla-ansible/provision/openstack-kolla.sh b/vagrant--kolla-ansible/provision/openstack-kolla.sh new file mode 100755 index 0000000..a5bbb17 --- /dev/null +++ b/vagrant--kolla-ansible/provision/openstack-kolla.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# Ref. https://docs.openstack.org/kolla-ansible/latest/user/quickstart.html + +# Paranoia mode +set -e +set -u + +## +## Install prerequisites +## +sudo apt install -y git python3-dev libffi-dev gcc libssl-dev ufw +sudo apt install -y git python3-pip python3-venv + +# Create sudo user for openstack -- not needed (vagrant is the same) +# useradd -s /bin/bash -d /opt/stack -m stack +# chmod +x /opt/stack +# apt-get install sudo -y +# echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack + +## +## Create the virtual environment +## +KOLLA_VENV_PATH=$HOME/kolla-venv +python3 -m venv "$KOLLA_VENV_PATH" + . "$KOLLA_VENV_PATH/bin/activate" +pip install -U pip +pip install 'ansible>=4,<6' + +## +## Install Kolla-ansible +## + +pip install git+https://opendev.org/openstack/kolla-ansible@master +sudo mkdir -p /etc/kolla +sudo mkdir -p /etc/kolla/globals.d +sudo chown -R "$USER:$USER" /etc/kolla + +cp -r "$KOLLA_VENV_PATH/share/kolla-ansible/etc_examples/kolla"/* /etc/kolla +cp "$KOLLA_VENV_PATH/share/kolla-ansible/ansible/inventory/all-in-one" . + +kolla-ansible install-deps +kolla-genpwd + +## +## Configure globals +## +IP_ADDR="$(ip addr show dev eth0 |sed -n '/inet / { s,.*inet ,, ; s,/.*,, ; s,\.[0-9]\+$,.250, ; p }')" +cat > /etc/kolla/globals.d/default.yml <<-MARK +kolla_base_distro: "debian" +openstack_tag_suffix: "" +network_interface: "eth0" +neutron_external_interface: "ext0" +kolla_internal_vip_address: "$IP_ADDR" +# +MARK + + +## +## Deploy +## + +# create fake network interface +IFACE_FILE="$(mktemp)" +cat > "$IFACE_FILE"<<-MARK +auto ext0 +iface ext0 inet manual + ## Keep unconfigured for kolla + pre-up ip link add dev ext0 type dummy + pre-up ip link set state up dev ext0 + pre-up ip link set state down dev ext0 + post-down ip link del dev ext0 +MARK +sudo chown root:root "$IFACE_FILE" +sudo mv "$IFACE_FILE" /etc/network/interfaces.d/ext0 +sudo ifup ext0 || true +## systemctl restart networking + +echo "== boostrap" +kolla-ansible -i ./all-in-one bootstrap-servers +echo "== prechecks" +kolla-ansible -i ./all-in-one prechecks +echo "== deploy" +kolla-ansible -i ./all-in-one deploy + +pip install python-openstackclient -c https://releases.openstack.org/constraints/upper/master +# FIMXE: generate & show password +#