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.
What You'll Learn
- Deploy a web server apache httpd on Debian-like systems
- code
- execution
- idempotency
- before execution
- after execution
- Conclusion
- Related Articles
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
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 4 min
- Category: installation
Read the full written article: Set Up Apache Webserver on Debian with Ansible Playbook
Related Video Tutorials
- Deploy Apache HTTPD on Docker Container with Ansible — Automate the deployment of Apache HTTPD in a Docker container using Ansible. Manage system packages, Docker images, and web content effortlessly.
- Set Up Apache Vhost on Debian with Ansible Playbook — Learn to configure an Apache virtual host on Debian using Ansible. Automate web server setup, document root creation, and firewall rules.
- Deploy Apache HTTPD with Podman Using Ansible Playbook — Automate Apache HTTPD deployment in a Podman container with Ansible. Manage Podman installation, image pulling, and container configuration.
- Deploy Apache HTTPD Container with Podman via Ansible — Automate the deployment of Apache HTTPD in a Podman container using Ansible. Set up web root, custom index.html, and manage container settings.
- Efficient Web Server Setup Using Ansible Playbook — Set up a web server effortlessly with our Ansible playbook tutorial. Follow step-by-step instructions for installing and configuring HTTPD service.
- Configure Apache Vhost on RedHat Using Ansible Playbook — Automate Apache virtual host setup on RedHat systems with Ansible. Learn to manage web server installation, configuration, and firewall settings.