Skip to content

[DEV] Create some virtual machines with Vagrant and Ansible

License

Notifications You must be signed in to change notification settings

mborne/vagrantbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vagrantbox

Create some virtual machines with Vagrant and Ansible.

Motivation

This repository aims at providing a playground :

Requirements

  • VirtualBox or KVM
  • Vagrant
  • Ansible if you want to use helper playbooks
  • Optional (http proxy) : vagrant plugin install vagrant-proxyconf to forward HTTP_PROXY, HTTPS_PROXY and NO_PROXY.

Parameters

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"

Usage

Vagrant

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

see also gist.github.com - wpscholar/vagrant-cheat-sheet.md

Ansible

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 :

asciicast

License

MIT

Ressources

About

[DEV] Create some virtual machines with Vagrant and Ansible

Topics

Resources

License

Stars

Watchers

Forks