diff --git a/.gitignore b/.gitignore index 28c4dfb..577f6b0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ ansible/files/* __pycache__ + +.vagrant diff --git a/Makefile b/Makefile index e7ceec1..f3d03ae 100644 --- a/Makefile +++ b/Makefile @@ -46,3 +46,26 @@ init-terraform: cleanup: rm -r $(TF_PLUGINS_DIR)/$(ARCHIVE) + + +init-test-env: + vagrant up + # Warning : this add a test key into the admin + ssh-keygen -y -f .vagrant/machines/default/virtualbox/private_key >> $(HOME)/.ansible/roles/infra-role-bootstrap-linux/files/keys/admin.pub + ansible-playbook ansible/bootstrap.yml \ + --inventory ansible/inventory/test \ + --extra-vars '@ansible/group_vars/test.yml' \ + --tags role::bootstrap:packages,role::bootstrap:docker,role::bootstrap:firewall,role::bootstrap:users,role::bootstrap:logging + + + +test-run-upgrade: + ansible-playbook ansible/upgrade.yml \ + --inventory ansible/inventory/test \ + --extra-vars '@ansible/group_vars/test.yml' + +clean-test-env: + vagrant destroy + rm -r .vagrant + +test: init-test-env test-run-upgrade clean-test-env diff --git a/README.md b/README.md index 72b7b6f..1ed9130 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,29 @@ # Repo Usage For how to use this repo read the [Infra Repo Usage](https://github.com/status-im/infra-docs/blob/master/docs/general/infra_repo_usage.md) doc. + +# Test + +## Prerequisites + +To run the test environement, you need to have installed + +* [vagrant](https://www.vagrantup.com/) +* [VirtualBox](https://www.virtualbox.org/) + +> **Note**: It's opssible to use another virtualization hypervisor, in that case, you need to modify the Vagrantfile accordingly. + +## Launch + +The command ``make test`` will launch the following actions: + +* `init-test-env` : Create the VM, add the user ssh public key into the `admin.pub` file of `infra-role-bootstrap-linux`, run the linux bootstraping of the VM (tags for `packages`, `role`, `docker`, `firewall`, `user`, `logging`) +* `test-run-upgrade`: Example of plabook to run +* `clean-text-env`: Delete the VM, and remove the `.vagrant` directory. + +## Adapt to project + +* Modify the `ansible/inventory/test` to add host group matching the playbook you want to run. +* Add function in the Makefile for each playbook you want to run. + +> **Warning**: The test VM doesn't not install consul on the host, some part of the playbook might failed. Use tags to specify witch role to execute. diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..9aad328 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,19 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + + config.vm.box = "ubuntu/focal64" + + # Resource configuration + config.vm.provider "virtualbox" do |v| + v.memory=4096 + v.cpus= 2 + end + + # Networking +# config.vm.define "vm" do |vm| +# vm.vm.hostname="test-node" +# end + +end diff --git a/ansible/group_vars/test.yml b/ansible/group_vars/test.yml new file mode 100644 index 0000000..8688cfa --- /dev/null +++ b/ansible/group_vars/test.yml @@ -0,0 +1,4 @@ +--- +ansible_ssh_private_key_file: .vagrant/machines/default/virtualbox/private_key +ansible_user: vagrant + diff --git a/ansible/inventory/test b/ansible/inventory/test new file mode 100644 index 0000000..6b961eb --- /dev/null +++ b/ansible/inventory/test @@ -0,0 +1,2 @@ +[all] +test hostname=localhost ansible_host=127.0.0.1 ansible_port=2222 env=test stage=test data_center=test region=test dns_entry=test.statusim.net