This project automates the creation, configuration, and management of virtual machines (VMs) using Vagrant and Ansible. You can optionally extend this automation by integrating Terraform for provisioning cloud infrastructure. VMs are configured to install Python, Docker, and Nginx for application deployment.
- Automation Setup Guide
Before running this project, make sure the following tools are installed:
- Vagrant (for local VMs)
- Virtualization Provider (e.g., VirtualBox, Parallels, etc.)
- Ansible (for configuration management)
- Terraform (optional for provisioning cloud resources)
- Python3 (required for running tests and Ansible)
.
├── ansible/ # Ansible configuration
│ ├── ansible.cfg # Ansible configuration file
│ ├── ansible.log # Log file for Ansible operations
│ ├── group_vars/ # Variables for all hosts
│ │ └── all/
│ │ └── vault.yml # Encrypted sensitive variables using Ansible Vault
│ ├── host_vars/ # Host-specific variables
│ │ ├── cosmos.yml
│ │ ├── nebula.yml
│ │ ├── pulsar.yml
│ │ ├── quasar.yml
│ │ └── supernova.yml
│ ├── inventory/
│ │ └── hosts # Inventory file for defining the hosts
│ ├── playbooks/
│ │ └── site.yml # Main Ansible playbook
│ └── roles/ # Ansible roles
│ ├── docker/ # Docker role
│ ├── nginx/ # Nginx role
│ ├── python/ # Python installation role
│ ├── python3/ # Python3-specific role
│ └── mdklatt.tmpdir/ # External role for managing temp dirs
├── scripts/ # Helper scripts
│ ├── manage_ansible.sh # Script to manage Ansible
│ └── manage_vagrant.sh # Script to manage Vagrant
├── terraform/ # Terraform configuration (optional)
│ ├── main.tf
│ ├── playbook.yml
│ └── variables.tf
└── vagrant/
└── Vagrantfile # Vagrant configuration file
You can start the VMs by running the provided manage_vagrant.sh
script:
./scripts/manage_vagrant.sh up
Run the Ansible playbook to install Python, Docker, and Nginx on the VMs:
./scripts/manage_ansible.sh run
- Ping All VMs:
ansible all -i ansible/inventory/hosts -m ping
- Check Logs:
cat ansible/ansible.log
To manage sensitive variables in vault.yml
, use Ansible Vault:
- Encrypt Variables:
ansible-vault encrypt ansible/group_vars/all/vault.yml
- Edit Vault:
ansible-vault edit ansible/group_vars/all/vault.yml
Some roles have testing configurations (e.g., python3
). To run these tests:
cd ansible/roles/python3/tests
pytest
- Initialize Terraform:
cd terraform
terraform init
- Apply the Terraform Plan:
terraform apply
This will provision the infrastructure and trigger the Ansible playbook using local-exec
.
Terraform is integrated to provision cloud infrastructure. Modify variables.tf
and main.tf
to match your environment. The playbook.yml
in the terraform/
directory ensures Ansible is executed post-provisioning.
manage_vagrant.sh
– Used to manage the lifecycle of Vagrant VMs (up, halt, destroy).manage_ansible.sh
– Used to execute Ansible playbooks.
- Python Version Issues: Ensure the correct Python version is installed on the VMs.
- VM Issues: Verify that the virtualization provider (e.g., VirtualBox, Parallels) is correctly installed.