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 servic