AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Set Up Apache Webserver on Debian with Ansible Playbook — Video Tutorial

Learn to deploy and configure an Apache web server on Debian using Ansible. Automate installation, custom index.html setup, and firewall rules.

Watch Video

Watch "Set Up Apache Webserver on Debian with Ansible Playbook" on YouTube

What You'll Learn

Full Tutorial Content

How to deploy a webserver apache httpd on Debian-like systems with Ansible? I'm going to show you a live Playbook with some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot. Deploy a web server apache httpd on Debian-like systems - install packages => `ansible.builtin.apt` - custom index.html => `ansible.builtin.copy` - start service => `ansible.builtin.service` - open firewall => `community.general.ufw` Today we're talking about how to Deploy a web server apache httpd on Debian-like Linux systems. The full process requires six steps that you could automate with different Ansible modules. Firstly you need to install the `apache2` package and dependency using the `ansible.builtin.apt` Ansible module. Secondly, you need to create the custom index.html with `ansible.builtin.copy` Ansible module. You could upgrade this step using the `template` module. Thirsty you need to start the `apache2` service and enable it on boot and all the dependant using the `ansible.builtin.service` Ansible module. Fourthly you need to open the relevant firewall service-related ports using the `community.general.ufw` Ansible module. ## Playbook How to deploy a web server apache httpd on Debian-like systems with Ansible Playbook. code ```yaml --- - name: setup webserver hosts: all become: true tasks: - name: apache installed ansible.builtin.apt: name: apache2 update_cache: true state: latest - name: custom index.html ansible.builtin.copy: dest: "/var/www/html/index.html" content: | Custom Web Page - name: apache2 service enabled ansible.builtin.service: name: apache2 enabled: true state: started - name: open firewall community.general.ufw: rule: allow port: 80 proto: tcp ``` execution ```bash ansible-pilot $ ansible-playbook -i virtualmachines/ubuntu/inventory services/httpd_debian.yml PLAY [setup webserver] **************************************************************************** TASK [Gathering Facts] **************************************************************************** ok: [ubuntu.example.com] TASK [apache installed] *************************************************************************** changed: [ubuntu.example.com] TASK [custom index.html] ************************************************************************** changed: [ubuntu.example.com] TASK [apache2 service enabled] ******************************************************************** ok: [ubuntu.example.com] TASK [open firewall] ****************************************************************************** changed: [ubuntu.example.com] PLAY RECAP **************************************************************************************** ubuntu.example.com : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible-pilot $ ``` idempotency ```bash ansible-pilot $ ans

About This Tutorial

Read the full written article: Set Up Apache Webserver on Debian with Ansible Playbook

Topics Covered

Related Video Tutorials