This guide installs a Hexo build environment with Node.js and serves static output with Nginx.
It supports Debian 10 to latest stable, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Hexo
hosts: hexo
become: true
vars:
hexo_root: /opt/hexo-site
tasks:
- name: Install dependencies on Debian/Ubuntu
apt:
name:
- nodejs
- npm
- nginx
- curl
- git
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install dependencies on RHEL family
dnf:
name:
- nodejs
- npm
- nginx
- curl
- git
state: present
when: ansible_os_family == "RedHat"
- name: Ensure Nginx is enabled and started
service:
name: nginx
state: started
enabled: true
- name: Create Hexo project root
file:
path: "{{ hexo_root }}"
state: directory
mode: "0755"
- name: Install Hexo CLI globally
npm:
name: hexo-cli
global: true
- name: Check whether package.json exists
stat:
path: "{{ hexo_root }}/package.json"
register: hexo_package_json
- name: Install project dependencies if package.json exists
command: npm install
args:
chdir: "{{ hexo_root }}"
when: hexo_package_json.stat.exists
- name: Build Hexo site if package.json exists
command: npx hexo generate
args:
chdir: "{{ hexo_root }}"
when: hexo_package_json.stat.exists
public/.We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact