Initial
This commit is contained in:
37
.gitignore
vendored
Normal file
37
.gitignore
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# Vagrant
|
||||
.vagrant/
|
||||
Vagrantfile.local
|
||||
|
||||
# Backup files
|
||||
backup-*/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
*.temp
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# IDE files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# Kubernetes
|
||||
*.kubeconfig
|
||||
join-command.sh
|
||||
|
||||
# Helm
|
||||
charts/
|
||||
*.tgz
|
||||
117
Makefile
Normal file
117
Makefile
Normal file
@@ -0,0 +1,117 @@
|
||||
# Bare Bones Vagrant Makefile
|
||||
|
||||
.PHONY: help start stop destroy status ssh-host ssh-machine1 ssh-machine2 ssh-machine3 ssh-machine4 clean \
|
||||
ansible-ping ansible-setup ansible-deploy ansible-list ansible-facts \
|
||||
reset-full reset-destroy reset-start reset-test reset-ssh reset-ansible reset-setup reset-deploy
|
||||
|
||||
# Default target
|
||||
help: ## Show this help message
|
||||
@echo "Bare Bones Vagrant Management"
|
||||
@echo "============================"
|
||||
@echo ""
|
||||
@echo "Available targets:"
|
||||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
|
||||
start: ## Start all machines
|
||||
@echo "Starting all machines..."
|
||||
./manage.sh start
|
||||
|
||||
stop: ## Stop all machines
|
||||
@echo "Stopping all machines..."
|
||||
./manage.sh stop
|
||||
|
||||
destroy: ## Destroy all machines (permanent)
|
||||
@echo "Destroying all machines..."
|
||||
./manage.sh destroy
|
||||
|
||||
status: ## Show machine status
|
||||
@echo "Showing machine status..."
|
||||
./manage.sh status
|
||||
|
||||
ssh-host: ## Access host machine via SSH
|
||||
@echo "Accessing host machine..."
|
||||
./manage.sh ssh host
|
||||
|
||||
ssh-machine1: ## Access machine1 via SSH
|
||||
@echo "Accessing machine1..."
|
||||
./manage.sh ssh machine1
|
||||
|
||||
ssh-machine2: ## Access machine2 via SSH
|
||||
@echo "Accessing machine2..."
|
||||
./manage.sh ssh machine2
|
||||
|
||||
ssh-machine3: ## Access machine3 via SSH
|
||||
@echo "Accessing machine3..."
|
||||
./manage.sh ssh machine3
|
||||
|
||||
ssh-machine4: ## Access machine4 via SSH
|
||||
@echo "Accessing machine4..."
|
||||
./manage.sh ssh machine4
|
||||
|
||||
clean: ## Clean up temporary files
|
||||
@echo "Cleaning up temporary files..."
|
||||
rm -rf backup-* *.log *.tmp *.temp
|
||||
@echo "Cleanup complete!"
|
||||
|
||||
# Quick access targets
|
||||
host: ssh-host ## Alias for ssh-host
|
||||
m1: ssh-machine1 ## Alias for ssh-machine1
|
||||
m2: ssh-machine2 ## Alias for ssh-machine2
|
||||
m3: ssh-machine3 ## Alias for ssh-machine3
|
||||
m4: ssh-machine4 ## Alias for ssh-machine4
|
||||
|
||||
# Ansible targets
|
||||
ansible-ping: ## Test Ansible connectivity to all hosts
|
||||
@echo "Testing Ansible connectivity..."
|
||||
ansible all -i inventory -m ping
|
||||
|
||||
ansible-setup: ## Run setup playbook to install dependencies
|
||||
@echo "Installing Ansible roles..."
|
||||
ansible-galaxy install -r ansible-requirements.yml --force
|
||||
@echo "Running setup playbook..."
|
||||
ansible-playbook -i inventory setup-playbook.yml
|
||||
|
||||
ansible-deploy: ## Run deployment playbook
|
||||
@echo "Running deployment playbook..."
|
||||
ansible-playbook -i inventory deploy-playbook.yml
|
||||
|
||||
ansible-list: ## List all hosts in inventory
|
||||
@echo "Listing all hosts..."
|
||||
ansible all -i inventory --list-hosts
|
||||
|
||||
ansible-facts: ## Gather facts from all hosts
|
||||
@echo "Gathering facts from all hosts..."
|
||||
ansible all -i inventory -m setup
|
||||
|
||||
# Reset and Test targets
|
||||
reset-full: ## Full destroy/recreate/test cycle
|
||||
@echo "Running full reset and test cycle..."
|
||||
./reset-and-test.sh full-reset
|
||||
|
||||
reset-destroy: ## Only destroy all machines
|
||||
@echo "Destroying all machines..."
|
||||
./reset-and-test.sh destroy-only
|
||||
|
||||
reset-start: ## Only start all machines
|
||||
@echo "Starting all machines..."
|
||||
./reset-and-test.sh start-only
|
||||
|
||||
reset-test: ## Only run tests (assumes machines are running)
|
||||
@echo "Running tests..."
|
||||
./reset-and-test.sh test-only
|
||||
|
||||
reset-ssh: ## Only test SSH connectivity
|
||||
@echo "Testing SSH connectivity..."
|
||||
./reset-and-test.sh ssh-test
|
||||
|
||||
reset-ansible: ## Only test Ansible connectivity
|
||||
@echo "Testing Ansible connectivity..."
|
||||
./reset-and-test.sh ansible-test
|
||||
|
||||
reset-setup: ## Only run setup playbook
|
||||
@echo "Running setup playbook..."
|
||||
./reset-and-test.sh setup-only
|
||||
|
||||
reset-deploy: ## Only run deployment playbook
|
||||
@echo "Running deployment playbook..."
|
||||
./reset-and-test.sh deploy-only
|
||||
263
README.md
Normal file
263
README.md
Normal file
@@ -0,0 +1,263 @@
|
||||
# Bare Bones Vagrant Setup
|
||||
|
||||
A **ultra-lightweight** Vagrant setup with 4 machines and a host for basic testing and development.
|
||||
|
||||
## ⚡ Ultra-Lightweight Features
|
||||
|
||||
- **512MB RAM per machine** - Minimal memory footprint
|
||||
- **Debian Linux base** - ~150MB base image, ~400MB with tools
|
||||
- **No provisioning scripts** - Pure Debian base
|
||||
- **No shared folders** - Disabled for performance
|
||||
- **Minimal network** - Just basic connectivity
|
||||
- **Fast startup** - Debian boots quickly
|
||||
|
||||
## 🏗️ Architecture
|
||||
|
||||
```
|
||||
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
||||
│ host │ │ machine1 │ │ machine2 │ │ machine3 │
|
||||
│ 192.168.56.1│ │192.168.56.10│ │192.168.56.11│ │192.168.56.12│
|
||||
│ │ │ │ │ │ │ │
|
||||
│ - Host │ │ - Machine 1 │ │ - Machine 2 │ │ - Machine 3 │
|
||||
│ - Gateway │ │ - Debian │ │ - Debian │ │ - Debian │
|
||||
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
|
||||
│
|
||||
┌─────────────┐
|
||||
│ machine4 │
|
||||
│192.168.56.13│
|
||||
│ │
|
||||
│ - Machine 4 │
|
||||
│ - Debian │
|
||||
└─────────────┘
|
||||
```
|
||||
|
||||
## 📋 Prerequisites
|
||||
|
||||
- **Vagrant** 2.2+
|
||||
- **VirtualBox** 6.0+ or **libvirt** (KVM)
|
||||
- **3GB+ RAM** (512MB per machine)
|
||||
- **4GB+ free disk space**
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
1. **Start all machines:**
|
||||
```bash
|
||||
make start
|
||||
```
|
||||
|
||||
2. **Check status:**
|
||||
```bash
|
||||
make status
|
||||
```
|
||||
|
||||
3. **Access a machine:**
|
||||
```bash
|
||||
make ssh-host
|
||||
make ssh-machine1
|
||||
```
|
||||
|
||||
## 🎛️ Management Commands
|
||||
|
||||
### Using Make
|
||||
```bash
|
||||
make start # Start all machines
|
||||
make stop # Stop all machines
|
||||
make destroy # Destroy all machines
|
||||
make status # Show machine status
|
||||
make ssh-host # Access host machine
|
||||
make ssh-machine1 # Access machine1
|
||||
make ssh-machine2 # Access machine2
|
||||
make ssh-machine3 # Access machine3
|
||||
make ssh-machine4 # Access machine4
|
||||
```
|
||||
|
||||
### Using Management Script
|
||||
```bash
|
||||
./manage.sh start # Start all machines
|
||||
./manage.sh stop # Stop all machines
|
||||
./manage.sh destroy # Destroy all machines
|
||||
./manage.sh status # Show machine status
|
||||
./manage.sh ssh host # Access host machine
|
||||
./manage.sh ssh machine1 # Access machine1
|
||||
```
|
||||
|
||||
### Using Vagrant Directly
|
||||
```bash
|
||||
vagrant up # Start all machines
|
||||
vagrant halt # Stop all machines
|
||||
vagrant destroy -f # Destroy all machines
|
||||
vagrant status # Show machine status
|
||||
vagrant ssh host # Access host machine
|
||||
vagrant ssh machine1 # Access machine1
|
||||
```
|
||||
|
||||
## 🌐 Network Configuration
|
||||
|
||||
- **Host**: 192.168.56.1
|
||||
- **Machine 1**: 192.168.56.10
|
||||
- **Machine 2**: 192.168.56.11
|
||||
- **Machine 3**: 192.168.56.12
|
||||
- **Machine 4**: 192.168.56.13
|
||||
|
||||
All machines are connected via a private network and can communicate with each other.
|
||||
|
||||
## 🔧 Machine Specifications
|
||||
|
||||
- **OS**: Debian 11 (Bullseye)
|
||||
- **RAM**: 512MB per machine + 1GB swap
|
||||
- **CPU**: 1 core per machine
|
||||
- **Disk**: 8GB per machine
|
||||
|
||||
## 📁 Project Structure
|
||||
|
||||
```
|
||||
test-vagrant/
|
||||
├── Vagrantfile # Debian Linux cluster configuration
|
||||
├── manage.sh # Management script
|
||||
├── Makefile # Make targets
|
||||
├── inventory # Ansible inventory file
|
||||
├── setup-playbook.yml # Setup playbook (dependencies, Python, swap)
|
||||
├── deploy-playbook.yml # Deployment playbook (apps, services)
|
||||
├── README.md # This file
|
||||
└── .gitignore # Git ignore rules
|
||||
```
|
||||
|
||||
## 🛠️ Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Machines not starting:**
|
||||
```bash
|
||||
vagrant status
|
||||
vagrant up --debug
|
||||
```
|
||||
|
||||
2. **Network issues:**
|
||||
```bash
|
||||
vagrant ssh host -c "ping 192.168.56.10"
|
||||
```
|
||||
|
||||
3. **SSH issues:**
|
||||
```bash
|
||||
vagrant ssh-config
|
||||
```
|
||||
|
||||
### Useful Commands
|
||||
|
||||
```bash
|
||||
# Check machine status
|
||||
vagrant status
|
||||
|
||||
# View machine details
|
||||
vagrant ssh-config
|
||||
|
||||
# Reload machines
|
||||
vagrant reload
|
||||
|
||||
# Provision machines
|
||||
vagrant provision
|
||||
```
|
||||
|
||||
## 🐧 Debian Linux Notes
|
||||
|
||||
### **Package Management**
|
||||
```bash
|
||||
# Update package index
|
||||
apt update
|
||||
|
||||
# Install packages
|
||||
apt install package-name
|
||||
|
||||
# Search packages
|
||||
apt search keyword
|
||||
```
|
||||
|
||||
### **Common Debian Commands**
|
||||
```bash
|
||||
# Check system info
|
||||
uname -a
|
||||
cat /etc/os-release
|
||||
|
||||
# Check memory usage
|
||||
free -m
|
||||
|
||||
# Check disk usage
|
||||
df -h
|
||||
```
|
||||
|
||||
## 🎭 Ansible Integration
|
||||
|
||||
### **Prerequisites**
|
||||
```bash
|
||||
# Install Ansible (on your host machine)
|
||||
pip install ansible
|
||||
|
||||
# Or on Ubuntu/Debian
|
||||
sudo apt install ansible
|
||||
```
|
||||
|
||||
### **Ansible Commands**
|
||||
```bash
|
||||
# Test connectivity to all hosts
|
||||
make ansible-ping
|
||||
|
||||
# Install dependencies (Python, tools, swap)
|
||||
make ansible-setup
|
||||
|
||||
# Deploy applications and services
|
||||
make ansible-deploy
|
||||
|
||||
# List all hosts
|
||||
make ansible-list
|
||||
|
||||
# Gather system facts
|
||||
make ansible-facts
|
||||
```
|
||||
|
||||
### **Using Management Script**
|
||||
```bash
|
||||
# Test Ansible connectivity
|
||||
./manage.sh ansible ping
|
||||
|
||||
# Install dependencies
|
||||
./manage.sh ansible setup
|
||||
|
||||
# Deploy applications
|
||||
./manage.sh ansible deploy
|
||||
```
|
||||
|
||||
### **Direct Ansible Commands**
|
||||
```bash
|
||||
# Test connectivity
|
||||
ansible all -i inventory -m ping
|
||||
|
||||
# Run setup playbook
|
||||
ansible-playbook -i inventory setup-playbook.yml
|
||||
|
||||
# Run deployment playbook
|
||||
ansible-playbook -i inventory deploy-playbook.yml
|
||||
|
||||
# Run on specific hosts
|
||||
ansible-playbook -i inventory deploy-playbook.yml --limit machines
|
||||
|
||||
# Run with verbose output
|
||||
ansible-playbook -i inventory deploy-playbook.yml -v
|
||||
```
|
||||
|
||||
## 🚀 Next Steps
|
||||
|
||||
This is a bare-bones Debian setup. You can extend it by:
|
||||
|
||||
1. **Adding provisioning scripts** to install Debian packages
|
||||
2. **Setting up networking** between machines
|
||||
3. **Installing Docker** (Debian has excellent Docker support)
|
||||
4. **Adding lightweight services** (nginx, redis, etc.)
|
||||
5. **Setting up monitoring** with lightweight tools
|
||||
|
||||
## 📄 License
|
||||
|
||||
This project is licensed under the MIT License.
|
||||
|
||||
---
|
||||
|
||||
**Ultra-Lightweight Debian! 🐧⚡**
|
||||
119
Vagrantfile
vendored
Normal file
119
Vagrantfile
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
# Global configuration
|
||||
config.vm.box = "debian/bookworm64"
|
||||
config.vm.box_version = ">= 12.12.0"
|
||||
|
||||
# Disable automatic box update checking
|
||||
config.vm.box_check_update = false
|
||||
|
||||
# Configure SSH
|
||||
config.ssh.insert_key = true
|
||||
|
||||
# Configure shared folders
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
|
||||
# Configure provider-specific settings
|
||||
config.vm.provider "virtualbox" do |vb|
|
||||
vb.name = "bare-bones-cluster"
|
||||
vb.memory = "512"
|
||||
vb.cpus = 1
|
||||
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
|
||||
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
|
||||
end
|
||||
|
||||
# Configure libvirt provider
|
||||
config.vm.provider "libvirt" do |libvirt|
|
||||
libvirt.memory = 512
|
||||
libvirt.cpus = 1
|
||||
libvirt.driver = "kvm"
|
||||
libvirt.connect_via_ssh = false
|
||||
end
|
||||
|
||||
# Host Machine
|
||||
config.vm.define "host" do |host|
|
||||
host.vm.hostname = "host"
|
||||
host.vm.network "private_network", ip: "192.168.56.1"
|
||||
|
||||
host.vm.provider "virtualbox" do |vb|
|
||||
vb.name = "host"
|
||||
vb.memory = "512"
|
||||
vb.cpus = 1
|
||||
end
|
||||
|
||||
host.vm.provider "libvirt" do |libvirt|
|
||||
libvirt.memory = 512
|
||||
libvirt.cpus = 1
|
||||
end
|
||||
end
|
||||
|
||||
# Machine 1
|
||||
config.vm.define "machine1" do |machine1|
|
||||
machine1.vm.hostname = "machine1"
|
||||
machine1.vm.network "private_network", ip: "192.168.56.10"
|
||||
|
||||
machine1.vm.provider "virtualbox" do |vb|
|
||||
vb.name = "machine1"
|
||||
vb.memory = "512"
|
||||
vb.cpus = 1
|
||||
end
|
||||
|
||||
machine1.vm.provider "libvirt" do |libvirt|
|
||||
libvirt.memory = 512
|
||||
libvirt.cpus = 1
|
||||
end
|
||||
end
|
||||
|
||||
# Machine 2
|
||||
config.vm.define "machine2" do |machine2|
|
||||
machine2.vm.hostname = "machine2"
|
||||
machine2.vm.network "private_network", ip: "192.168.56.11"
|
||||
|
||||
machine2.vm.provider "virtualbox" do |vb|
|
||||
vb.name = "machine2"
|
||||
vb.memory = "512"
|
||||
vb.cpus = 1
|
||||
end
|
||||
|
||||
machine2.vm.provider "libvirt" do |libvirt|
|
||||
libvirt.memory = 512
|
||||
libvirt.cpus = 1
|
||||
end
|
||||
end
|
||||
|
||||
# Machine 3
|
||||
config.vm.define "machine3" do |machine3|
|
||||
machine3.vm.hostname = "machine3"
|
||||
machine3.vm.network "private_network", ip: "192.168.56.12"
|
||||
|
||||
machine3.vm.provider "virtualbox" do |vb|
|
||||
vb.name = "machine3"
|
||||
vb.memory = "512"
|
||||
vb.cpus = 1
|
||||
end
|
||||
|
||||
machine3.vm.provider "libvirt" do |libvirt|
|
||||
libvirt.memory = 512
|
||||
libvirt.cpus = 1
|
||||
end
|
||||
end
|
||||
|
||||
# Machine 4
|
||||
config.vm.define "machine4" do |machine4|
|
||||
machine4.vm.hostname = "machine4"
|
||||
machine4.vm.network "private_network", ip: "192.168.56.13"
|
||||
|
||||
machine4.vm.provider "virtualbox" do |vb|
|
||||
vb.name = "machine4"
|
||||
vb.memory = "512"
|
||||
vb.cpus = 1
|
||||
end
|
||||
|
||||
machine4.vm.provider "libvirt" do |libvirt|
|
||||
libvirt.memory = 512
|
||||
libvirt.cpus = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
6
ansible-requirements.yml
Normal file
6
ansible-requirements.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
# Ansible Galaxy Requirements
|
||||
# Install with: ansible-galaxy install -r ansible-requirements.yml
|
||||
|
||||
- name: geerlingguy.swap
|
||||
version: 1.1.1
|
||||
132
deploy-playbook.yml
Normal file
132
deploy-playbook.yml
Normal file
@@ -0,0 +1,132 @@
|
||||
---
|
||||
# Deployment Playbook for Debian Linux
|
||||
# This playbook deploys applications and services
|
||||
|
||||
- name: Deploy applications on Debian Linux
|
||||
hosts: alpine
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
|
||||
tasks:
|
||||
- name: Update apt package index
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: Install Docker
|
||||
apt:
|
||||
name:
|
||||
- docker.io
|
||||
- docker-compose
|
||||
state: present
|
||||
|
||||
- name: Add vagrant user to docker group
|
||||
user:
|
||||
name: vagrant
|
||||
groups: docker
|
||||
append: yes
|
||||
|
||||
- name: Start and enable Docker service
|
||||
systemd:
|
||||
name: docker
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: Test Docker installation
|
||||
command: docker --version
|
||||
register: docker_version
|
||||
changed_when: false
|
||||
|
||||
- name: Show Docker version
|
||||
debug:
|
||||
msg: "{{ docker_version.stdout }}"
|
||||
|
||||
- name: Pull a lightweight test image
|
||||
docker_image:
|
||||
name: alpine:latest
|
||||
source: pull
|
||||
|
||||
- name: Run a test container
|
||||
docker_container:
|
||||
name: test-container
|
||||
image: alpine:latest
|
||||
command: echo "Docker is working on {{ inventory_hostname }}!"
|
||||
state: present
|
||||
auto_remove: yes
|
||||
|
||||
- name: Create application directory
|
||||
file:
|
||||
path: /opt/app
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Create sample application
|
||||
copy:
|
||||
content: |
|
||||
#!/bin/bash
|
||||
echo "Hello from {{ inventory_hostname }}!"
|
||||
echo "Running on Debian Linux"
|
||||
echo "Memory: $(free -m | grep Mem | awk '{print $2}')MB"
|
||||
echo "Disk: $(df -h / | tail -1 | awk '{print $2}')"
|
||||
dest: /opt/app/hello.sh
|
||||
mode: '0755'
|
||||
|
||||
- name: Create systemd service for sample app
|
||||
copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Sample Application
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=vagrant
|
||||
ExecStart=/opt/app/hello.sh
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
dest: /etc/systemd/system/sample-app.service
|
||||
mode: '0644'
|
||||
|
||||
- name: Reload systemd daemon
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
|
||||
- name: Enable sample application service
|
||||
systemd:
|
||||
name: sample-app
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Check service status
|
||||
command: systemctl status sample-app
|
||||
register: service_status
|
||||
changed_when: false
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Show service status
|
||||
debug:
|
||||
msg: "{{ service_status.stdout_lines }}"
|
||||
|
||||
- name: Create deployment info file
|
||||
copy:
|
||||
content: |
|
||||
Deployment completed on {{ inventory_hostname }}
|
||||
Date: {{ ansible_date_time.iso8601 }}
|
||||
OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
|
||||
Architecture: {{ ansible_architecture }}
|
||||
Memory: {{ ansible_memtotal_mb }}MB
|
||||
Docker: {{ docker_version.stdout }}
|
||||
dest: /opt/app/deployment-info.txt
|
||||
mode: '0644'
|
||||
|
||||
- name: Display deployment info
|
||||
command: cat /opt/app/deployment-info.txt
|
||||
register: deployment_info
|
||||
changed_when: false
|
||||
|
||||
- name: Show deployment info
|
||||
debug:
|
||||
msg: "{{ deployment_info.stdout_lines }}"
|
||||
22
inventory
Normal file
22
inventory
Normal file
@@ -0,0 +1,22 @@
|
||||
# Ansible Inventory for Alpine Vagrant Cluster
|
||||
# This file defines the hosts and groups for Ansible playbooks
|
||||
|
||||
[all:vars]
|
||||
ansible_user=vagrant
|
||||
ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
||||
|
||||
[hosts]
|
||||
host ansible_host=127.0.0.1 ansible_port=2222 ansible_ssh_private_key_file=.vagrant/machines/host/virtualbox/private_key
|
||||
|
||||
[machines]
|
||||
machine1 ansible_host=127.0.0.1 ansible_port=2200 ansible_ssh_private_key_file=.vagrant/machines/machine1/virtualbox/private_key
|
||||
machine2 ansible_host=127.0.0.1 ansible_port=2201 ansible_ssh_private_key_file=.vagrant/machines/machine2/virtualbox/private_key
|
||||
machine3 ansible_host=127.0.0.1 ansible_port=2202 ansible_ssh_private_key_file=.vagrant/machines/machine3/virtualbox/private_key
|
||||
machine4 ansible_host=127.0.0.1 ansible_port=2203 ansible_ssh_private_key_file=.vagrant/machines/machine4/virtualbox/private_key
|
||||
|
||||
[alpine:children]
|
||||
hosts
|
||||
machines
|
||||
|
||||
[alpine:vars]
|
||||
ansible_python_interpreter=/usr/bin/python3
|
||||
164
manage.sh
Executable file
164
manage.sh
Executable file
@@ -0,0 +1,164 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Bare Bones Vagrant Management Script
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo -e "${BLUE}=== $1 ===${NC}"
|
||||
}
|
||||
|
||||
# Function to start all machines
|
||||
start_all() {
|
||||
print_header "Starting All Machines"
|
||||
vagrant up
|
||||
print_status "All machines started successfully!"
|
||||
}
|
||||
|
||||
# Function to stop all machines
|
||||
stop_all() {
|
||||
print_header "Stopping All Machines"
|
||||
vagrant halt
|
||||
print_status "All machines stopped successfully!"
|
||||
}
|
||||
|
||||
# Function to destroy all machines
|
||||
destroy_all() {
|
||||
print_header "Destroying All Machines"
|
||||
print_warning "This will permanently delete all machines!"
|
||||
read -p "Are you sure? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
vagrant destroy -f
|
||||
print_status "All machines destroyed successfully!"
|
||||
else
|
||||
print_status "Operation cancelled."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show status
|
||||
show_status() {
|
||||
print_header "Machine Status"
|
||||
vagrant status
|
||||
}
|
||||
|
||||
# Function to access a specific machine
|
||||
access_machine() {
|
||||
local machine=${1:-host}
|
||||
print_header "Accessing $machine"
|
||||
vagrant ssh "$machine"
|
||||
}
|
||||
|
||||
# Function to run Ansible commands
|
||||
run_ansible() {
|
||||
local command=${1:-ping}
|
||||
print_header "Running Ansible $command"
|
||||
|
||||
case "$command" in
|
||||
ping)
|
||||
ansible all -i inventory -m ping
|
||||
;;
|
||||
setup)
|
||||
ansible-playbook -i inventory setup-playbook.yml
|
||||
;;
|
||||
deploy)
|
||||
ansible-playbook -i inventory deploy-playbook.yml
|
||||
;;
|
||||
list)
|
||||
ansible all -i inventory --list-hosts
|
||||
;;
|
||||
facts)
|
||||
ansible all -i inventory -m setup
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown Ansible command: $command"
|
||||
print_status "Available commands: ping, setup, deploy, list, facts"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to show help
|
||||
show_help() {
|
||||
echo "Bare Bones Vagrant Management Script"
|
||||
echo ""
|
||||
echo "Usage: $0 [COMMAND] [MACHINE]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " start Start all machines"
|
||||
echo " stop Stop all machines"
|
||||
echo " destroy Destroy all machines (permanent)"
|
||||
echo " status Show machine status"
|
||||
echo " ssh MACHINE Access machine via SSH"
|
||||
echo " ansible COMMAND Run Ansible command (ping, play, docker, list, facts)"
|
||||
echo " help Show this help message"
|
||||
echo ""
|
||||
echo "Machines:"
|
||||
echo " host Host machine (192.168.56.1)"
|
||||
echo " machine1 Machine 1 (192.168.56.10)"
|
||||
echo " machine2 Machine 2 (192.168.56.11)"
|
||||
echo " machine3 Machine 3 (192.168.56.12)"
|
||||
echo " machine4 Machine 4 (192.168.56.13)"
|
||||
echo ""
|
||||
echo "Ansible Commands:"
|
||||
echo " ping Test connectivity to all hosts"
|
||||
echo " setup Install dependencies (Python, tools, swap)"
|
||||
echo " deploy Deploy applications and services"
|
||||
echo " list List all hosts"
|
||||
echo " facts Gather system facts"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 start # Start all machines"
|
||||
echo " $0 ssh host # Access host machine"
|
||||
echo " $0 ansible ping # Test Ansible connectivity"
|
||||
echo " $0 ansible setup # Install dependencies"
|
||||
echo " $0 ansible deploy # Deploy applications"
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
case "${1:-help}" in
|
||||
start)
|
||||
start_all
|
||||
;;
|
||||
stop)
|
||||
stop_all
|
||||
;;
|
||||
destroy)
|
||||
destroy_all
|
||||
;;
|
||||
status)
|
||||
show_status
|
||||
;;
|
||||
ssh)
|
||||
access_machine "$2"
|
||||
;;
|
||||
ansible)
|
||||
run_ansible "$2"
|
||||
;;
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown command: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
344
reset-and-test.sh
Executable file
344
reset-and-test.sh
Executable file
@@ -0,0 +1,344 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Reset and Test Script for Debian Vagrant Cluster
|
||||
# This script fully destroys and recreates the entire stack, then runs all tests
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_header() {
|
||||
echo -e "${BLUE}=== $1 ===${NC}"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✅ $1${NC}"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}❌ $1${NC}"
|
||||
}
|
||||
|
||||
print_info() {
|
||||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||||
}
|
||||
|
||||
# Function to check if command exists
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to wait for user confirmation (disabled for automation)
|
||||
confirm() {
|
||||
print_info "Auto-confirming operation (automation mode)"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to check prerequisites
|
||||
check_prerequisites() {
|
||||
print_header "Checking Prerequisites"
|
||||
|
||||
local missing_deps=()
|
||||
|
||||
if ! command_exists vagrant; then
|
||||
missing_deps+=("vagrant")
|
||||
fi
|
||||
|
||||
if ! command_exists ansible; then
|
||||
missing_deps+=("ansible")
|
||||
fi
|
||||
|
||||
if ! command_exists make; then
|
||||
missing_deps+=("make")
|
||||
fi
|
||||
|
||||
if [ ${#missing_deps[@]} -ne 0 ]; then
|
||||
print_error "Missing required dependencies: ${missing_deps[*]}"
|
||||
print_info "Please install the missing dependencies and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "All prerequisites are installed"
|
||||
}
|
||||
|
||||
# Function to destroy everything
|
||||
destroy_all() {
|
||||
print_header "Destroying All Machines"
|
||||
|
||||
print_info "Auto-confirming destruction (automation mode)"
|
||||
|
||||
print_info "Stopping all machines..."
|
||||
vagrant halt 2>/dev/null || true
|
||||
|
||||
print_info "Destroying all machines..."
|
||||
vagrant destroy -f
|
||||
|
||||
print_info "Cleaning up Vagrant files..."
|
||||
rm -rf .vagrant/
|
||||
|
||||
print_success "All machines destroyed and cleaned up"
|
||||
}
|
||||
|
||||
# Function to start all machines
|
||||
start_all() {
|
||||
print_header "Starting All Machines"
|
||||
|
||||
print_info "Starting Vagrant cluster..."
|
||||
vagrant up
|
||||
|
||||
print_info "Waiting for machines to be ready..."
|
||||
sleep 10
|
||||
|
||||
print_info "Checking machine status..."
|
||||
vagrant status
|
||||
|
||||
print_success "All machines started successfully"
|
||||
}
|
||||
|
||||
# Function to test SSH connectivity
|
||||
test_ssh() {
|
||||
print_header "Testing SSH Connectivity"
|
||||
|
||||
local machines=("host" "machine1" "machine2" "machine3" "machine4")
|
||||
local failed_machines=()
|
||||
|
||||
for machine in "${machines[@]}"; do
|
||||
print_info "Testing SSH to $machine..."
|
||||
if vagrant ssh "$machine" -c "echo 'SSH test successful'" >/dev/null 2>&1; then
|
||||
print_success "SSH to $machine: OK"
|
||||
else
|
||||
print_error "SSH to $machine: FAILED"
|
||||
failed_machines+=("$machine")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#failed_machines[@]} -ne 0 ]; then
|
||||
print_error "SSH failed for: ${failed_machines[*]}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_success "All SSH connections working"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to test Ansible connectivity
|
||||
test_ansible() {
|
||||
print_header "Testing Ansible Connectivity"
|
||||
|
||||
print_info "Running Ansible ping test..."
|
||||
if ansible all -i inventory -m ping; then
|
||||
print_success "Ansible connectivity test passed"
|
||||
return 0
|
||||
else
|
||||
print_error "Ansible connectivity test failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run setup playbook
|
||||
run_setup() {
|
||||
print_header "Running Setup Playbook"
|
||||
|
||||
print_info "Installing Ansible roles..."
|
||||
if ansible-galaxy install -r ansible-requirements.yml --force; then
|
||||
print_success "Ansible roles installed successfully"
|
||||
else
|
||||
print_error "Failed to install Ansible roles"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_info "Installing dependencies and creating swap..."
|
||||
if ansible-playbook -i inventory setup-playbook.yml; then
|
||||
print_success "Setup playbook completed successfully"
|
||||
return 0
|
||||
else
|
||||
print_error "Setup playbook failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run deployment playbook
|
||||
run_deployment() {
|
||||
print_header "Running Deployment Playbook"
|
||||
|
||||
print_info "Deploying applications and services..."
|
||||
if ansible-playbook -i inventory deploy-playbook.yml; then
|
||||
print_success "Deployment playbook completed successfully"
|
||||
return 0
|
||||
else
|
||||
print_error "Deployment playbook failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run comprehensive tests
|
||||
run_tests() {
|
||||
print_header "Running Comprehensive Tests"
|
||||
|
||||
local test_results=()
|
||||
|
||||
# Test 1: SSH Connectivity
|
||||
if test_ssh; then
|
||||
test_results+=("SSH: ✅ PASS")
|
||||
else
|
||||
test_results+=("SSH: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 2: Ansible Connectivity
|
||||
if test_ansible; then
|
||||
test_results+=("Ansible: ✅ PASS")
|
||||
else
|
||||
test_results+=("Ansible: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 3: Setup Playbook
|
||||
if run_setup; then
|
||||
test_results+=("Setup: ✅ PASS")
|
||||
else
|
||||
test_results+=("Setup: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 4: Deployment Playbook
|
||||
if run_deployment; then
|
||||
test_results+=("Deployment: ✅ PASS")
|
||||
else
|
||||
test_results+=("Deployment: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 5: Verify swap is active
|
||||
print_info "Verifying swap is active..."
|
||||
if ansible all -i inventory -m shell -a "cat /proc/swaps" | grep -q "swapfile"; then
|
||||
test_results+=("Swap: ✅ PASS")
|
||||
else
|
||||
test_results+=("Swap: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 6: Verify Docker is running
|
||||
print_info "Verifying Docker is running..."
|
||||
if ansible all -i inventory -m shell -a "docker --version" >/dev/null 2>&1; then
|
||||
test_results+=("Docker: ✅ PASS")
|
||||
else
|
||||
test_results+=("Docker: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Display test results
|
||||
print_header "Test Results Summary"
|
||||
for result in "${test_results[@]}"; do
|
||||
echo " $result"
|
||||
done
|
||||
|
||||
# Count failures
|
||||
local failures=$(printf '%s\n' "${test_results[@]}" | grep -c "❌ FAIL" || true)
|
||||
|
||||
if [ "$failures" -eq 0 ]; then
|
||||
print_success "All tests passed! 🎉"
|
||||
return 0
|
||||
else
|
||||
print_error "$failures test(s) failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show help
|
||||
show_help() {
|
||||
echo "Reset and Test Script for Debian Vagrant Cluster"
|
||||
echo ""
|
||||
echo "Usage: $0 [COMMAND]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " full-reset Destroy everything and run full test cycle"
|
||||
echo " destroy-only Only destroy all machines"
|
||||
echo " start-only Only start all machines"
|
||||
echo " test-only Only run tests (assumes machines are running)"
|
||||
echo " ssh-test Only test SSH connectivity"
|
||||
echo " ansible-test Only test Ansible connectivity"
|
||||
echo " setup-only Only run setup playbook"
|
||||
echo " deploy-only Only run deployment playbook"
|
||||
echo " help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 full-reset # Complete destroy/recreate/test cycle"
|
||||
echo " $0 test-only # Run tests on existing machines"
|
||||
echo " $0 ssh-test # Quick SSH connectivity check"
|
||||
echo ""
|
||||
echo "This script will:"
|
||||
echo " 1. Check prerequisites (vagrant, ansible, make)"
|
||||
echo " 2. Destroy all VMs and clean up"
|
||||
echo " 3. Start all VMs fresh"
|
||||
echo " 4. Test SSH connectivity"
|
||||
echo " 5. Test Ansible connectivity"
|
||||
echo " 6. Run setup playbook (dependencies, swap)"
|
||||
echo " 7. Run deployment playbook (Docker, services)"
|
||||
echo " 8. Verify everything is working"
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
main() {
|
||||
local command=${1:-help}
|
||||
|
||||
case "$command" in
|
||||
full-reset)
|
||||
print_header "Full Reset and Test Cycle"
|
||||
check_prerequisites
|
||||
destroy_all
|
||||
start_all
|
||||
run_tests
|
||||
;;
|
||||
destroy-only)
|
||||
print_header "Destroy Only"
|
||||
check_prerequisites
|
||||
destroy_all
|
||||
;;
|
||||
start-only)
|
||||
print_header "Start Only"
|
||||
check_prerequisites
|
||||
start_all
|
||||
;;
|
||||
test-only)
|
||||
print_header "Test Only"
|
||||
check_prerequisites
|
||||
run_tests
|
||||
;;
|
||||
ssh-test)
|
||||
print_header "SSH Test Only"
|
||||
check_prerequisites
|
||||
test_ssh
|
||||
;;
|
||||
ansible-test)
|
||||
print_header "Ansible Test Only"
|
||||
check_prerequisites
|
||||
test_ansible
|
||||
;;
|
||||
setup-only)
|
||||
print_header "Setup Only"
|
||||
check_prerequisites
|
||||
run_setup
|
||||
;;
|
||||
deploy-only)
|
||||
print_header "Deploy Only"
|
||||
check_prerequisites
|
||||
run_deployment
|
||||
;;
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown command: $command"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function with all arguments
|
||||
main "$@"
|
||||
98
setup-playbook.yml
Normal file
98
setup-playbook.yml
Normal file
@@ -0,0 +1,98 @@
|
||||
---
|
||||
# Setup Playbook for Debian Linux
|
||||
# This playbook installs essential dependencies including Python and creates swap
|
||||
|
||||
- name: Setup Debian Linux hosts
|
||||
hosts: alpine
|
||||
become: yes
|
||||
gather_facts: no
|
||||
|
||||
vars:
|
||||
swap_file_size_mb: 1024
|
||||
swap_file_state: present
|
||||
swap_file_existing_size_mb: 0
|
||||
|
||||
roles:
|
||||
- role: geerlingguy.swap
|
||||
swap_file_size_mb: 1024
|
||||
swap_file_state: present
|
||||
|
||||
tasks:
|
||||
- name: Update apt package index
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: Install essential packages
|
||||
apt:
|
||||
name:
|
||||
- python3
|
||||
- python3-pip
|
||||
- vim
|
||||
- curl
|
||||
- wget
|
||||
- htop
|
||||
- tree
|
||||
- git
|
||||
- openssh-client
|
||||
- sudo
|
||||
- util-linux
|
||||
state: present
|
||||
|
||||
- name: Create sudoers entry for vagrant user
|
||||
lineinfile:
|
||||
path: /etc/sudoers.d/vagrant
|
||||
line: "vagrant ALL=(ALL) NOPASSWD:ALL"
|
||||
create: yes
|
||||
mode: '0440'
|
||||
|
||||
- name: Install Python packages
|
||||
pip:
|
||||
name:
|
||||
- ansible
|
||||
state: present
|
||||
become_user: vagrant
|
||||
|
||||
- name: Verify Python installation
|
||||
command: python3 --version
|
||||
register: python_version
|
||||
changed_when: false
|
||||
|
||||
- name: Show Python version
|
||||
debug:
|
||||
msg: "{{ python_version.stdout }}"
|
||||
|
||||
- name: Verify pip installation
|
||||
command: pip3 --version
|
||||
register: pip_version
|
||||
changed_when: false
|
||||
|
||||
- name: Show pip version
|
||||
debug:
|
||||
msg: "{{ pip_version.stdout }}"
|
||||
|
||||
- name: Create test directory
|
||||
file:
|
||||
path: /home/vagrant/test
|
||||
state: directory
|
||||
owner: vagrant
|
||||
group: vagrant
|
||||
mode: '0755'
|
||||
|
||||
- name: Display system information
|
||||
command: uname -a
|
||||
register: system_info
|
||||
changed_when: false
|
||||
|
||||
- name: Show system information
|
||||
debug:
|
||||
msg: "{{ system_info.stdout }}"
|
||||
|
||||
- name: Check memory and swap usage
|
||||
command: free -m
|
||||
register: memory_info
|
||||
changed_when: false
|
||||
|
||||
- name: Show memory and swap usage
|
||||
debug:
|
||||
msg: "{{ memory_info.stdout_lines }}"
|
||||
Reference in New Issue
Block a user