This project demonstrates a local development environment setup using Vagrant, Docker, and Ansible. It creates a virtual machine running two Apache web servers behind an Nginx reverse proxy, all containerized using Docker.
The setup consists of:
- A Vagrant-managed Ubuntu 20.04 LTS virtual machine
- Two Apache web servers running in Docker containers
- An Nginx reverse proxy (also in a Docker container) routing traffic to the Apache servers
- Ansible for automating the provisioning and configuration of the environment
- Vagrant (2.2.x or later)
- VirtualBox (6.1.x or later)
- Ansible (2.9.x or later, installed on your host machine)
Vagrantfile: Defines the virtual machine configuration and provisioning stepsmain.yml: Ansible playbook for setting up Docker containers and testing the setupdocker-compose.yml: Defines the Docker services (Nginx and Apache containers)nginx.conf: Nginx reverse proxy configurationindex1.html,index2.html: Sample web pages for Apache containers
-
Clone this repository:
git clone https://github.com/teddy0605/devops-interview-project.git cd devops-interview-project -
Start the Vagrant VM and provision it:
vagrant up 2>&1 | tee vagrant.logThis command will create the VM, install necessary software, and run the Ansible playbook to set up the Docker containers.
After the installation is complete, you can access the web servers in two ways:
-
Direct access to specific backends:
-
Random load balancing:
Accessing the IP address directly will randomly forward your request to either web1 or web2 backend.
Replace 192.168.56.10 with the IP address specified in your Vagrantfile if you've modified it.
To manually test the setup:
-
SSH into the Vagrant VM:
vagrant ssh -
Run the Ansible playbook:
ansible-playbook /vagrant/main.yml
This will run through the setup steps and perform tests to ensure the web services are accessible.
If you encounter issues:
- Ensure all prerequisites are correctly installed.
- Check the Vagrant and Ansible output for specific error messages.
- Verify that the Docker containers are running inside the VM:
vagrant ssh -c "docker ps" - Check the Nginx logs:
vagrant ssh -c "docker logs nginx"
- To modify the web content, edit
index1.htmlandindex2.html. - To change the Nginx configuration, modify
nginx.conf. - To alter the Docker setup, edit
docker-compose.yml.
To stop and remove the Vagrant VM:
vagrant destroy -f