Back to site

Install Ansible

Install Ansible on a HolyCloud VPS to automate server configuration and deploy playbooks.

Install Ansible

Ansible automates server configuration over SSH, without an agent on target machines. On a HolyCloud Linux VPS, install it on a control node (bastion) that manages this VPS and other servers (second VPS, staging, etc.).

Prerequisites

  • HolyCloud VPS Ubuntu/Debian with Python 3 and sudo access
  • SSH keys configured toward target hosts (ssh-copy-id)
  • Port 22 open to targets (UFW + HolyCloud firewall)

PPA or official Ubuntu packages:

sudo apt update
sudo apt install -y ansible sshpass
ansible --version

On Debian 12:

sudo apt install -y ansible-core sshpass

Step 2: install via pip (newer version)

For a newer isolated version:

sudo apt install -y python3-pip python3-venv
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate
pip install --upgrade pip ansible
ansible --version

Add to ~/.bashrc:

source ~/ansible-venv/bin/activate

Step 3: project structure

mkdir -p ~/ansible/{inventory,playbooks,roles}
cd ~/ansible

Simple inventory /inventory/hosts.ini:

[vps_holycloud]
vps-prod ansible_host=203.0.113.10 ansible_user=deploy

[vps_holycloud:vars]
ansible_python_interpreter=/usr/bin/python3

Replace with the public IP of your VPS shown in the HolyCloud customer area.

Step 4: first playbook

File playbooks/ping.yml:

---
- name: Test connectivité VPS HolyCloud
  hosts: vps_holycloud
  gather_facts: yes
  tasks:
    - name: Ping module
      ansible.builtin.ping:

    - name: Afficher hostname
      ansible.builtin.debug:
        msg: "Serveur {{ inventory_hostname }} = {{ ansible_hostname }}"

Run:

cd ~/ansible
ansible-playbook -i inventory/hosts.ini playbooks/ping.yml

Ad hoc test:

ansible -i inventory/hosts.ini vps_holycloud -m shell -a 'uptime'

Step 5: useful playbook — base packages

playbooks/base.yml:

---
- name: Configuration de base
  hosts: vps_holycloud
  become: yes
  tasks:
    - name: Mettre à jour le cache apt
      ansible.builtin.apt:
        update_cache: yes
        cache_valid_time: 3600

    - name: Installer paquets essentiels
      ansible.builtin.apt:
        name:
          - curl
          - git
          - ufw
          - fail2ban
        state: present

    - name: Autoriser SSH dans UFW
      community.general.ufw:
        rule: allow
        name: OpenSSH

    - name: Activer UFW
      community.general.ufw:
        state: enabled

UFW collection:

ansible-galaxy collection install community.general
ansible-playbook -i inventory/hosts.ini playbooks/base.yml

Step 6: HolyCloud best practices

  • Store inventory and vaults outside public Git; use ansible-vault for secrets
  • Limit the control node by IP (your office or a dedicated admin VPS)
  • A single VPS can be both target and controller for small fleets

Local ansible.cfg:

[defaults]
inventory = inventory/hosts.ini
host_key_checking = False
retry_files_enabled = False

In production, enable host_key_checking and known_hosts.

Verification

ansible --version
ansible -i inventory/hosts.ini all -m ping
ansible-config dump | head -20

Need help?

  • UNREACHABLE: IP, HolyCloud firewall, SSH key, ansible_user
  • Permission denied: become: yes and sudo on the target
  • HolyCloud support: ansible-playbook -vvv output, controller source IP, UFW rules