AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 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 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", 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.

Efficient Web Server Setup Using Ansible Playbook — Video Tutorial

Set up a web server effortlessly with our Ansible playbook tutorial. Follow step-by-step instructions for installing and configuring HTTPD service.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • How to deploy a webserver apache httpd on RedHat-like systems with Ansible?
  • Deploy a web server apache httpd on RedHat-like systems
  • code
  • execution
  • idempotency
  • before execution
  • after execution
  • Conclusion
  • Related Articles
How to deploy a webserver apache httpd on RedHat-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 RedHat-like systems - install packages => `ansible.builtin.yum` - custom index.html => `ansible.builtin.copy` - start service => `ansible.builtin.service` - open firewall => `ansible.posix.firewalld` Today we're talking about how to Deploy a web server apache httpd on RedHat-like Linux systems. The full process requires four steps that you could automate with different Ansible modules. Firstly you need to install the `httpd` package and dependency using the `ansible.builtin.yum` 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 `httpd` service and enable 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 `ansible.posix.firewalld` Ansible module. ## Playbook Deploy a web server apache httpd on RedHat-like systems with Ansible Playbook. code ```yaml --- - name: setup webserver hosts: all become: true tasks: - name: httpd installed ansible.builtin.yum: name: httpd state: latest - name: custom index.html ansible.builtin.copy: dest: /var/www/html/index.html content: | Custom Web Page - name: httpd service enabled ansible.builtin.service: name: httpd enabled: true state: started - name: open firewall ansible.posix.firewalld: service: http state: enabled immediate: true permanent: true ``` execution ```bash ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory services/httpd_redhat.yml PLAY [setup webserver] **************************************************************************** TASK [Gathering Facts] **************************************************************************** ok: [demo.example.com] TASK [httpd installed] **************************************************************************** changed: [demo.example.com] TASK [custom index.html] ************************************************************************** changed: [demo.example.com] TASK [httpd service enabled] ********************************************************************** changed: [demo.example.com] TASK [open firewall] ****************************************************************************** changed: [demo.example.com] PLAY RECAP **************************************************************************************** demo.example.com : ok=5 changed=4 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible-pilot $ ``` idempotency ```bash ansible-pilot $ ansible-playbook -

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 3 min
  • Category: installation

Topics covered

Related video tutorials