This guide provides a full Ansible playbook to install Lighttpd with distro-aware package handling and baseline service configuration for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Lighttpd
hosts: lighttpd
become: true
vars:
lighttpd_packages_debian:
- lighttpd
- lighttpd-mod-fastcgi
lighttpd_packages_rhel:
- lighttpd
tasks:
- name: Install Lighttpd on Debian/Ubuntu
apt:
name: "{{ lighttpd_packages_debian }}"
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Lighttpd on RHEL family
dnf:
name: "{{ lighttpd_packages_rhel }}"
state: present
when: ansible_os_family == "RedHat"
- name: Enable and start service on Debian/Ubuntu
systemd:
name: lighttpd
state: started
enabled: true
when: ansible_os_family == "Debian"
- name: Enable and start service on RHEL
systemd:
name: lighttpd
state: started
enabled: true
when: ansible_os_family == "RedHat"
- name: Verify Lighttpd is installed
command: "lighttpd --version"
register: lighttpd_version
changed_when: false
failed_when: false
- name: Show Lighttpd version
debug:
var: lighttpd_version.stdout_lines
- name: Ensure latest security updates are applied
block:
- name: Update package cache (Debian/Ubuntu)
apt:
update_cache: yes
upgrade: dist
when: ansible_os_family == "Debian"
- name: Update packages (RHEL)
dnf:
update_cache: yes
upgrade: yes
when: ansible_os_family == "RedHat"
- name: Ensure latest Lighttpd version (Debian/Ubuntu)
apt:
name: lighttpd
state: latest
when: ansible_os_family == "Debian"
- name: Ensure latest Lighttpd version (RHEL)
dnf:
name: lighttpd
state: latest
when: ansible_os_family == "RedHat"
- name: Configure firewall (UFW)
ufw:
rule: allow
name: WWW
when:
- ansible_os_family == "Debian"
- ufw_status.stdout.find("Status: active") != -1
failed_when: false
- name: Configure firewall (firewalld)
firewalld:
service: "{{ item }}"
permanent: true
state: enabled
loop:
- http
- https
when: ansible_os_family == "RedHat"
failed_when: false
- name: Create document root
file:
path: /var/www/html
state: directory
mode: "0755"
owner: www-data
group: www-data
when: ansible_os_family == "Debian"
- name: Create document root (RHEL)
file:
path: /var/www/html
state: directory
mode: "0755"
owner: lighttpd
group: lighttpd
when: ansible_os_family == "RedHat"
Save the playbook as lighttpd_setup.yml and run:
ansible-playbook -i inventory.ini lighttpd_setup.yml
Package Names:
lighttpd, lighttpd-mod-fastcgilighttpd (EPEL repository required)Service Name:
lighttpdRHEL/EPEL: Lighttpd requires the EPEL repository on RHEL/CentOS
Debian baseline: Debian 10 works, but Debian 11/12 is preferred for package freshness
Ubuntu hint: Ubuntu 22.04+ is recommended for long-term maintenance
RHEL baseline: Use RHEL 9+ with EPEL enabled
Security Note: The playbook includes steps to ensure the latest security updates are applied (currently version 1.4.82+)
Version Verification: Check installed version with lighttpd --version
After running the playbook, verify Lighttpd is working:
# Check service status
sudo systemctl status lighttpd
# Check version
lighttpd --version
# Test web server
curl -I http://localhost
- name: Enable Lighttpd modules
command: "lighty-enable-mod {{ item }}"
loop:
- ssl
- fastcgi
- fastcgi-php
notify: restart lighttpd
when: ansible_os_family == "Debian"
handlers:
- name: restart lighttpd
systemd:
name: lighttpd
state: restarted
Beyond this playbook, we offer:
Contact our automation team: office@linux-server-admin.com