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.

Configure Apache Vhost on RedHat Using Ansible Playbook — Video Tutorial

Automate Apache virtual host setup on RedHat systems with Ansible. Learn to manage web server installation, configuration, and firewall settings.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • How to deploy a webserver apache httpd virtual host on RedHat-like systems with Ansible?
  • Deploy a web server apache httpd virtualhost on RedHat-like systems
  • code
  • execution
  • idempotency
  • before execution
  • after execution
  • Conclusion
  • Related Articles
How to deploy a webserver apache httpd virtual host on RedHat-like systems with Ansible? I'm going to show you a live Playbook with some simple Ansible code. This Playbook is quick and dirty but shows you the basics of Ansible automation technology that you could use in your System Administrator every day. I'm Luca Berton and welcome to today's episode of Ansible Pilot. Deploy a web server apache httpd virtualhost on RedHat-like systems - install packages => `ansible.builtin.yum` - document root => `ansible.builtin.file` - custom index.html => `ansible.builtin.copy` - Apache virtualhost => `ansible.builtin.template` - 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 six 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 document root with the right permission with the `ansible.builtin.file` module. Thirsty, you need to create the custom index.html with `ansible.builtin.copy` Ansible module. You could upgrade this step using the `template` module. Fourthly, you need to set up Apache configuration for the specific virtual host using the `ansible.builtin.template` module. Fifthly, you need to start the `httpd` service and enable it on boot and all the dependant using the `ansible.builtin.service` Ansible module. Sixthly you need to open the relevant firewall service-related ports using the `ansible.posix.firewalld` Ansible module. ## Playbook Deploy a web server apache httpd virtual host on RedHat-like systems with Ansible Playbook. code - httpd_redhat_vhost.yml ```yaml --- - name: setup webserver with vhost hosts: all become: true vars: app_user: "apache" http_host: "example.com" http_conf: "example.com.conf" http_port: "80" tasks: - name: httpd installed ansible.builtin.yum: name: httpd state: latest - name: document root exist ansible.builtin.file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' setype: "httpd_sys_content_t" - name: custom index.html ansible.builtin.copy: dest: "/var/www/{{ http_host }}/index.html" content: | Custom Web Page - name: setup Apache virtualhost ansible.builtin.template: src: "templates/httpd.conf.j2" dest: "/etc/httpd/conf.d/{{ http_conf }}" - name: httpd service enabled ansible.builtin.service: name: httpd enabled: true state: restarted - name: open firewall ansible.posix.firewalld: service: http state: enabled immediate: true permanent: true ``` - templates/httpd.conf.j2 ```bash <VirtualHost *:{{ http_port }}> Se

About this tutorial

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

Topics covered

Related video tutorials