This guide installs Ghost as a native Node.js application with systemd service management.
It supports Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible systems.
For a Docker-based installation, see Ghost Docker Ansible Setup.
- name: Install Ghost
hosts: ghost
become: true
vars:
ghost_user: ghost
ghost_group: ghost
ghost_home: /opt/ghost
ghost_version: "5.130.0"
ghost_port: 2368
ghost_url: "https://your-domain.com"
db_host: localhost
db_name: ghost
db_user: ghost
db_password: "change-me-strong-password"
tasks:
- name: Install dependencies on Debian/Ubuntu
apt:
name:
- nodejs
- npm
- mysql-server
- curl
- git
- build-essential
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install dependencies on RHEL family
dnf:
name:
- nodejs
- npm
- mariadb-server
- curl
- git
- gcc
- make
state: present
when: ansible_os_family == "RedHat"
- name: Enable and start MySQL/MariaDB
service:
name: "{{ 'mysql' if ansible_os_family == 'Debian' else 'mariadb' }}"
state: started
enabled: true
- name: Create Ghost database
mysql_db:
name: "{{ db_name }}"
state: present
login_unix_socket: "{{ '/var/run/mysqld/mysqld.sock' if ansible_os_family == 'Debian' else '/var/lib/mysql/mysql.sock' }}"
- name: Create Ghost database user
mysql_user:
name: "{{ db_user }}"
password: "{{ db_password }}"
priv: "{{ db_name }}.*:ALL"
state: present
login_unix_socket: "{{ '/var/run/mysqld/mysqld.sock' if ansible_os_family == 'Debian' else '/var/lib/mysql/mysql.sock' }}"
- name: Create Ghost system user
user:
name: "{{ ghost_user }}"
group: "{{ ghost_group }}"
system: true
create_home: false
- name: Create Ghost directory
file:
path: "{{ ghost_home }}"
state: directory
owner: "{{ ghost_user }}"
group: "{{ ghost_group }}"
mode: "0755"
- name: Install Ghost CLI globally
npm:
name: ghost-cli
global: true
state: present
- name: Install Ghost CMS
command: "ghost install {{ ghost_version }} --db mysql --dbhost {{ db_host }} --dbname {{ db_name }} --dbuser {{ db_user }} --dbpass {{ db_password }} --url {{ ghost_url }} --port {{ ghost_port }} --no-prompt --no-stack --no-setup-linux-user --no-setup-systemd"
args:
chdir: "{{ ghost_home }}"
become_user: "{{ ghost_user }}"
- name: Create systemd service for Ghost
copy:
dest: /etc/systemd/system/ghost.service
mode: "0644"
content: |
[Unit]
Description=Ghost CMS
After=network.target mysql.service
[Service]
Type=simple
User={{ ghost_user }}
Group={{ ghost_group }}
WorkingDirectory={{ ghost_home }}
Environment=NODE_ENV=production
ExecStart=/usr/bin/node {{ ghost_home }}/current/index.js
Restart=always
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
- name: Reload systemd daemon
systemd:
daemon_reload: true
- name: Enable and start Ghost service
service:
name: ghost
state: started
enabled: true
ghost_url variable to your actual domain name.--no-stack flag skips system checks; ensure prerequisites are met manually.Beyond this playbook, we offer:
Contact our automation team: office@linux-server-admin.com