Skip to content

p0tr3c/TerraKVM

Repository files navigation

TerraKVM

Build Status

Deploy VMs on KVM via docker/ansible/terraform

** Under development **
** Only tested on Arch Linux **
** Permissions issues between distros are likely **

Quick start

  1. Install libvirt [1],[2],[3], docker and docker-compose on the host
  2. cd TerraKVM
  3. Clone TerraKVM
  4. Per distribution:
    a. Arch Linux: Run sudo ./terrakvm preconfig to create default pool, and activate default network
  5. Deploy VM by running sudo ./terrakvm apply
  6. SSH to VM by running ssh -F dev.config dev
  7. To remove VM run sudo ./terrakvm destroy

For detailed usage instruction read USAGE.md

How does it work?

The project is a combination of ansible, terraform and jinja templates.

The terrakvm shell script is a wrapper around docker-compose which executes the ansible playbook in ansible/playbooks/ via docker container defined in docker/.

Ansible playbook executes role ansible/roles/ansible-role-terrakvm.

From high level point of view the role will template terraform configuration files via jinja2 templates.

You can find the templates in ansible/roles/ansible-role-terrakvm/templates/terraform.

Jinja will utilize variables defined in ansible/roles/ansible-role-terrakvm/defaults/main.yml

You can overwrite these variables from the command line just like in normal ansible execution.

The templates will generate terraform configuration for libvirt deployment. At the backend the terraform will utilize https://github.com/dmacvicar/terraform-provider-libvirt plugin for libvirt to deploy the vms.

As terraform utilizes state files to maintain state of the infrastructure, the project will create a directory under terraform/ for each deployment. Variable project_name defines the name of the new directory.

To destroy the infrastructure run terrakvm with destroy flag.

Demo

Video demonstration of the CentOS 7 x86_64 deployment

Note: the video is outdated

Requirements

  • libvirt
  • docker
  • docker-compose