Create some virtual machines with Vagrant and Ansible.
This repository aims at providing a playground :
- To install distributed systems like K3S
- To illustre the use of Vagrant and Ansible in mborne/cours-devops (French)
- VirtualBox or KVM
- Vagrant
- Ansible if you want to use helper playbooks
- Optional (http proxy) :
vagrant plugin install vagrant-proxyconf
to forwardHTTP_PROXY
,HTTPS_PROXY
andNO_PROXY
.
See supported env vars in Vagrantfile :
Name | Description | Default value |
---|---|---|
VAGRANTBOX_BOX |
Base image from Vagrant Cloud | "ubuntu/jammy64" |
VAGRANTBOX_NUM_NODES |
Number of VM | 4 |
VAGRANTBOX_NETWORK |
Network for VM | "192.168.50" |
VAGRANTBOX_MEMORY |
VM memory in Mo | "2048" |
Description | Command |
---|---|
Start VMs with VirtualBox | vagrant up |
Start VMs with KVM | VAGRANTBOX_BOX=generic/ubuntu2204 vagrant up --provider=libvirt |
Check VM status | vagrant status |
Open a terminal in a VM | vagrant ssh vagrantbox-1 |
Destroy VMs | vagrant destroy -f |
The following playbooks are available to configure guest and VMs :
Name | Description |
---|---|
playbooks/quickstart.yml | Apply the following playbooks |
playbooks/configure-vm.yml | Add ~/.ssh/id_rsa.pub and fill /etc/hosts on each VM |
playbooks/clear-ssh.yml | Update ~/.ssh/known_hosts with SSH keys for the vagrantbox VMs |
playbooks/upgrade.yml | Upgrade system package (apt-get update && apt-get upgrade -y ) |
playbooks/configure-host.yml | Fill /etc/hosts on VM's host (optional, see bellow) |
You may use playbooks/quickstart.yml as follow :
# /etc/hosts edition requires sudo
ansible-playbook -i inventory playbooks/quickstart.yml --ask-become-pass
# To avoid sudo requirement, disable changes on /etc/hosts :
ansible-playbook -i inventory playbooks/quickstart.yml -e configure_host_enabled=false
# With KVM and generic/ubuntu2204 :
ansible-playbook -i inventory playbooks/quickstart.yml -e vagrant_provider=libvirt -e ansible_ssh_pass=vagrant --ask-become-pass
You should see something like this :