Detailed Guide to Post-Cloud Init Automation: Automating 100 Identical VPS Setup from Boot
A detailed guide on transitioning after Cloud Init to automate the setup of 100 identical VPS instances from boot, covering network, user, SSH, and basic service configuration.
Image credit: wikimedia
Introduction
In DevOps environments, deploying multiple identical virtual private servers (VPS) is a common requirement. Cloud Init is the default tool on Linux systems for automating server configuration during boot. However, Cloud Init stops after the initial setup, making it difficult to maintain consistent configurations. This guide will walk you through how to transition after Cloud Init to automate the setup of 100 identical VPS instances from boot, ensuring consistency and reducing errors.
Understanding Cloud Init
Cloud Init is an open-source tool that enables Linux server configuration at boot time in cloud environments. It processes configurations provided via metadata or user-data files, including:
- Creating users and configuring SSH
- Setting up network configurations
- Installing software packages
- Running custom scripts
However, once the boot process completes, Cloud Init stops working. To maintain configuration consistency, you need to transition after Cloud Init using tools like Ansible, Puppet, or custom automation scripts.
Transitioning After Cloud Init: Step-by-Step Guide
To automate the setup of 100 identical VPS instances, follow these steps:
- Set up a base image (template) with the basic configuration.
- Create an automation script to apply post-boot configurations.
- Apply this script to all new VPS instances.
1. Create a Base Image
Start by launching a VPS with a Linux OS (Ubuntu/Debian/RHEL) and configure the basics:
- Admin user
- SSH key
- Essential packages (curl, wget, git, etc.)
- Network setup
Configure it only once, then create a snapshot to use as a template for other VPS instances.
2. Create an Automation Script
Develop a shell script to configure the system after boot. For example:
#!/bin/bash
# User configuration
useradd -m -s /bin/bash admin
echo "admin:password123" | chpasswd
# SSH configuration
mkdir -p /home/admin/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC..." > /home/admin/.ssh/authorized_keys
chown -R admin:admin /home/admin/.ssh
chmod 700 /home/admin/.ssh
chmod 600 /home/admin/.ssh/authorized_keys
# Install packages
apt update && apt install -y nginx curl git
# Run custom script
curl -s https://example.com/setup.sh | bash
# Restart services
systemctl restart nginx
3. Apply Script to 100 VPS Instances
In a cloud environment, use the provider’s API to create multiple VPS instances and pass the script via user-data:
# Example with a VPS provider API
curl -X POST https://api.vpsprovider.com/v1/vps \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "vps-001",
"image": "ubuntu-22.04-base",
"user_data": "#!/bin/bash\\nwget https://example.com/setup.sh -O /tmp/setup.sh\\nbash /tmp/setup.sh"
}'
Verification and Validation
After deployment, verify consistency across VPS instances:
- Run
ssh admin@vps-ipto test SSH connectivity. - Run
nginx -vto confirm Nginx is installed. - Run
systemctl status nginxto check the service status.
For bulk verification, use Ansible or a bash script:
#!/bin/bash
VPS_LIST=("192.168.1.101" "192.168.1.102" "192.168.1.103")
for ip in "${VPS_LIST[@]}"; do
ssh admin@$ip "nginx -v && systemctl status nginx"
done
Troubleshooting Common Issues
| Issue | Causes | Solutions |
|---|---|---|
| SSH connection fails | Incorrect SSH key or user not created | Review the user creation and SSH key setup in the script |
| Post-boot scripts fail | Cloud Init doesn't execute post-boot scripts | Transition after Cloud Init using Ansible or a dedicated automation tool |
| Script disconnects during execution | Script runs too long or contains errors | Break the script into smaller parts, add logging, and check for errors |
References
- Detailed Guide to Setting Up Distributed Monitoring with Grafana Alloy and Prometheus on VPS
- Detailed Guide to Host Multiple Websites on 1 VPS with Docker and Nginx Proxy Manager
- NVMe Cloud VPS for Docker, Nginx & Databases
Transitioning after Cloud Init enables you to automate the setup of 100 identical VPS instances, reducing deployment time and ensuring consistency. Apply these steps to efficiently scale your infrastructure.
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
