Deploy a simple "clock" web application (frontend + backend) in a virtual machine using ansible
.
debian10-ssh.img.tar.xz
: Compressed disk image of a virtual machine.vm.xml
: Virtual machine XML definition forlibvirt
rsa
: Authorized RSA key for accessing the virtual machineindex.html
: Frontend clock application
A script setup-prod.sh
has been built in order to automate:
- Downloading the compressed disk image file
- Extract the file and create a VM with that disk
- Connect to the VM via ansible and install docker and its dependancies [may take several minutes the first time]
- copy the app into the VM and deploy through docker
It automatically creates two new files in the project tree at:
./app/webserver/frontend/index.html
./vm/vm.xml
They are overwritten every time the automated script is invoked but they are needed if one wants to deploy by running ansible commands manually
After that the website should be available at: http:///
The following binaries need to be in $PATH:
- ansible
- ansible-playbook
In case we follow usage example 1 or 4 from Usage, following also required:
- virsh
The aforementioned script should be put in the project root's folder as is now, and executed after changing directory to root.
Use either as:
- Download VM and setup everything from scratch:
./setup.sh --auto
- Provide the reachable IP or FQDN/hostname of the already deployed VM, e.g:
./setup.sh --ip=192.168.122.188
- Provide the name of the already locally deployed VM (current: immfly-debian10), e.g:
./setup.sh --vm=immfly-debian10
- Provide the path to disk img file and auto create the VM, e.g:
./setup.sh --img=~/debian10-ssh.img
Cases 2 && 3 are almost identical with the only difference being, in case 3 it tries to figure out the ip based on the vm name provided.
In those cases no direct modifications are made to the VM itself, outside ansible's context.
Cases 1 && 4 differ only to the fact that in case 1 the disk file will be downloaded from the internet and extracted inside the project ./vm/
export DEBIAN10_IP=<the IP of the VM>
- Copy
./app/webserver/frontend/index-template.html
to./app/webserver/frontend/index.html
and change the IP here:
const CLOCK_URL = 'http://${BACKEND_ENDPOINT}/clock';
ansible-playbook ./ansible/setupvm.yml -i ./ansible/env/prod/inventory.yml
ansible-playbook ./ansible/deploy.yml -i ./ansible/env/prod/inventory.yml
The project is organized into the following dirs:
app
: The directory thats being copied to the VM via ansibleansible
: Ansible files, inventories, variables, roles, tasksvm
: Files needed to setup the VM instance itself: SSH keys and its libvirt definition
In ./ansible
folder right now only the prod
environment is used,
meaning its inventory and its variables, as well as the
env/group_00_global_vars
of course.
it would be better if we didn't need to keep templated files in
./app/webserver/frontent/index-template.html
./vm/vm-template.xml
a.o