Setting up a server by hand works once. The second time you forget a step; the third server ends up slightly different from the first. Ansible fixes this by describing the desired state of a server in plain YAML files that you run over SSH. Nothing needs to be installed on the server except Python, which Ubuntu and Debian already include. This guide builds a practical baseline playbook for a new VPS.
Why Ansible for a VPS?
- Repeatable: new servers, staging copies and replacements are configured identically.
- Documented: the playbook is the documentation of how the server is built.
- Idempotent: running it twice is safe; it only changes what is not already correct.
- Agentless: it uses SSH, so there is no extra daemon to secure on each server.
- Recoverable: if a server is lost, rebuild it from the playbook and restore data from backups.
Step 1: Install Ansible on Your Computer
# macOS
brew install ansible
# Linux or WSL
python3 -m pip install --user ansible
ansible --version
Windows users run Ansible inside WSL, because the control node must be Unix-like.
Step 2: Inventory
# inventory.ini
[web]
web1 ansible_host=203.0.113.10
[staging]
stage1 ansible_host=203.0.113.20
[all:vars]
ansible_user=root
ansible_python_interpreter=/usr/bin/python3
The first run connects as root (or the provider's initial user). After the playbook creates your own user and disables root login, change ansible_user to that user and add --become for privileged tasks.
ansible all -i inventory.ini -m ping
Step 3: A Baseline Playbook
# site.yml
- name: Baseline for every VPS
hosts: all
become: true
vars:
admin_user: deploy
admin_key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"
allowed_ports: ["80", "443"]
tasks:
- name: Update apt cache and upgrade packages
ansible.builtin.apt:
update_cache: true
upgrade: dist
cache_valid_time: 3600
- name: Install base packages
ansible.builtin.apt:
name: [ufw, unattended-upgrades, fail2ban, curl, htop]
state: present
- name: Create admin user
ansible.builtin.user:
name: "{{ admin_user }}"
groups: sudo
append: true
shell: /bin/bash
- name: Authorise SSH key
ansible.posix.authorized_key:
user: "{{ admin_user }}"
key: "{{ admin_key }}"
- name: Harden SSH
ansible.builtin.copy:
dest: /etc/ssh/sshd_config.d/00-hardening.conf
content: |
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
mode: "0644"
notify: Restart ssh
- name: Allow SSH through the firewall
community.general.ufw:
rule: limit
name: OpenSSH
- name: Allow web ports
community.general.ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop: "{{ allowed_ports }}"
- name: Enable firewall with deny-by-default
community.general.ufw:
state: enabled
policy: deny
direction: incoming
- name: Enable automatic security updates
ansible.builtin.copy:
dest: /etc/apt/apt.conf.d/20auto-upgrades
content: |
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
mode: "0644"
handlers:
- name: Restart ssh
ansible.builtin.service:
name: ssh
state: restarted
The SSH drop-in file name starts with 00- because OpenSSH uses the first value it reads for most options (see our SSH key guide). The firewall rule for SSH is added before the firewall is enabled, so you cannot lock yourself out (see our UFW guide). The ansible.posix and community.general collections are included in the full Ansible package; with ansible-core only, install them with ansible-galaxy collection install.
Step 4: Run It Safely
# preview what would change
ansible-playbook -i inventory.ini site.yml --check --diff
# apply
ansible-playbook -i inventory.ini site.yml
# limit to one server
ansible-playbook -i inventory.ini site.yml --limit stage1
Keep a second SSH session open the first time you apply SSH or firewall changes, and test logging in as the new user before closing it. After the first run, set ansible_user=deploy in the inventory.
Step 5: Organise with Roles
As playbooks grow, split them into roles, each with its own tasks, handlers, templates and default variables:
roles/
common/ # users, SSH, firewall, updates
nginx/ # web server and site templates
app/ # application user, systemd unit, deploys
site.yml # - hosts: web
# roles: [common, nginx, app]
Templates (Jinja2, .j2 files) let one Nginx site template serve production and staging with different variables such as server_name.
Step 6: Secrets with Ansible Vault
ansible-vault create group_vars/web/vault.yml
# inside:
vault_db_password: "a-long-random-password"
ansible-playbook -i inventory.ini site.yml --ask-vault-pass
Reference {{ vault_db_password }} in tasks and templates. The encrypted file is safe to commit; keep the vault password in a password manager. Mark tasks that handle secrets with no_log: true so values do not appear in output.
Ad-Hoc Commands for Everyday Tasks
Not everything needs a playbook. Ad-hoc commands run one module across many servers at once:
ansible web -i inventory.ini -m ansible.builtin.command -a "uptime"
ansible all -i inventory.ini --become -m ansible.builtin.apt -a "upgrade=dist update_cache=true"
ansible web -i inventory.ini --become -m ansible.builtin.service -a "name=nginx state=reloaded"
They are useful for quick checks and emergency patching; anything you repeat should become a playbook task.
Good Practices
- Use modules (
apt,copy,template,service) instead ofshellcommands, so tasks stay idempotent. - Run with
--check --diffbefore applying changes to production. - Keep playbooks in Git and review changes like code.
- Test new playbooks on a staging VPS first (see our staging guide).
- Re-run the playbook regularly to correct drift from manual changes.
SkyRainCloud Plans for This Workload
Ansible itself needs no resources on the servers beyond SSH and Python, so it works with every plan. Use it to rebuild any tier identically, or to keep a fleet of entry 2 vCore / 8 GB servers configured the same way.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Intel Xeon Platinum 8269CY VPS
KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check stock |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.
Frequently Asked Questions
Does Ansible need to be installed on the VPS?
Can I run Ansible from Windows?
What does idempotent mean in Ansible?
How do I avoid locking myself out with SSH or firewall tasks?
--check, keep a second SSH session open and confirm the new user can log in before closing it.How do I store passwords in Ansible?
no_log: true on tasks that handle them.Ansible or shell scripts?
Ansible or Terraform?
Can Ansible deploy my application?
How do I preview changes?
ansible-playbook --check --diff to see what would change without applying it.Which SkyRainCloud plans work with Ansible?
Related Guides
- How to Set Up SSH Key Authentication for a VPS on Windows, macOS and Linux
- How to Set Up a UFW Firewall on a Linux VPS
- How to Create a Staging Server for Web Applications Using a VPS
- How to Deploy Docker Containers on a VPS Server
- How to Migrate an Application to a New VPS with Minimal Downtime
- How to Setup a BungeeCord Network
- Instant Setup VPS India 2026
- Minecraft Server Hosting Pricing India (2026)