From 1fb9666e3324d4c67270f6dafb7d4b4d4c3c52a6 Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Sun, 21 Feb 2021 09:55:26 +0700 Subject: [PATCH] Replace multipass with vagrant --- .gitignore | 1 + README.md | 2 +- test/Makefile | 24 +++--------------------- test/README.md | 2 +- test/Vagrantfile | 22 ++++++++++++++++++++++ test/hosts.ini | 4 ++-- test/multipass-cloud-init.yaml | 10 ---------- 7 files changed, 30 insertions(+), 35 deletions(-) create mode 100644 test/Vagrantfile delete mode 100644 test/multipass-cloud-init.yaml diff --git a/.gitignore b/.gitignore index 1ef1f308..f44461f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vagrant/ .venv/ build/ diff --git a/README.md b/README.md index 9ab6f0a9..6f06a6d9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ For the controller (to run Ansible, stateless PXE server, Terraform...): - `python3` - Docker with `host` networking driver (which means [only Docker on Linux hosts](https://docs.docker.com/network/host/)) - `terraform` (0.14.x) -- `multipass` (optional, to create a [test environment](./test) locally) +- `vagrant` (optional, to create a local [test environment](./test)) For bare metal nodes: diff --git a/test/Makefile b/test/Makefile index a690980e..382522aa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,24 +1,9 @@ .POSIX: -NAME = metal - default: init metal infra init: - for count in 0 1; do \ - multipass list | grep $(NAME)$$count \ - || multipass launch \ - --cpus 2 \ - --mem 4G \ - --disk 64G \ - --cloud-init ./multipass-cloud-init.yaml \ - --name $(NAME)$$count \ - release:20.10; \ - multipass exec $(NAME)$$count -- sed -i "$$ a\$(shell cat ~/.ssh/id_rsa.pub)" /home/ubuntu/.ssh/authorized_keys; \ - done - -shell: - multipass shell $(NAME) + vagrant up metal: python3 -m venv .venv \ @@ -31,10 +16,7 @@ infra: echo infra stop: - multipass stop $(NAME) + vagrant halt clean: - for count in 0 1; do \ - multipass delete $(NAME)$$count; \ - done - multipass purge + vagrant destroy -f diff --git a/test/README.md b/test/README.md index 3ea5bdec..030e1527 100644 --- a/test/README.md +++ b/test/README.md @@ -1,6 +1,6 @@ # Test -Create a test environment in a Multipass VM (requires `multipass`) +Create a quick and dirty local test environment (requires `vagrant`) ```sh make diff --git a/test/Vagrantfile b/test/Vagrantfile new file mode 100644 index 00000000..63f2a964 --- /dev/null +++ b/test/Vagrantfile @@ -0,0 +1,22 @@ +Vagrant.configure("2") do |config| + config.vm.box = "debian/buster64" + + (0..1).each do |i| + config.vm.define "metal#{i}" do |metal| + metal.vm.network "private_network", ip: "192.168.50.#{i+2}" + end + end + + config.vm.provider "virtualbox" do |vb| + vb.cpus = 2 + vb.memory = "4096" + end + + config.vbguest.auto_update = false + + config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "/tmp/id_rsa.pub" + + config.vm.provision "shell", inline: <<-SHELL + cat /tmp/id_rsa.pub >> /home/vagrant/.ssh/authorized_keys + SHELL +end diff --git a/test/hosts.ini b/test/hosts.ini index f444f0a3..e19ded56 100644 --- a/test/hosts.ini +++ b/test/hosts.ini @@ -1,3 +1,3 @@ [metal] -metal0 ansible_host=192.168.64.6 ansible_user=ubuntu -metal1 ansible_host=192.168.64.7 ansible_user=ubuntu +metal0 ansible_host=192.168.50.2 ansible_user=vagrant +metal1 ansible_host=192.168.50.3 ansible_user=vagrant diff --git a/test/multipass-cloud-init.yaml b/test/multipass-cloud-init.yaml deleted file mode 100644 index 5c50e83d..00000000 --- a/test/multipass-cloud-init.yaml +++ /dev/null @@ -1,10 +0,0 @@ -#cloud-config - -runcmd: - - apt-get update - - curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add - - - apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main" - - curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - - - apt-add-repository "deb https://apt.kubernetes.io/ kubernetes-xenial main" - - apt-get update - - apt-get install -y kubectl terraform