<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: jay soni</title>
    <description>The latest articles on Forem by jay soni (@jay_soni_26).</description>
    <link>https://forem.com/jay_soni_26</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2558035%2F1d33b5af-c14d-491e-81da-d97a9f92603b.png</url>
      <title>Forem: jay soni</title>
      <link>https://forem.com/jay_soni_26</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jay_soni_26"/>
    <language>en</language>
    <item>
      <title>Automating Apache Web Server Deployment Using Ansible Roles 🚀</title>
      <dc:creator>jay soni</dc:creator>
      <pubDate>Wed, 14 Jan 2026 07:48:31 +0000</pubDate>
      <link>https://forem.com/jay_soni_26/automating-apache-web-server-deployment-using-ansible-roles-4o9</link>
      <guid>https://forem.com/jay_soni_26/automating-apache-web-server-deployment-using-ansible-roles-4o9</guid>
      <description>&lt;ul&gt;
&lt;li&gt;In this project, I demonstrate how to automate the installation, configuration, and deployment of a static website on an Apache Web Server using Ansible Roles.&lt;/li&gt;
&lt;li&gt;The project follows Ansible best practices and is structured to be reusable, modular, and production-ready.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;📌 Project Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main goal of this project is to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Automate Apache installation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy a static website&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use Ansible Roles for clean structure&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement handlers and variables&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure OS-based conditional execution&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This project is ideal for DevOps beginners and infrastructure automation use cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🛠 Tools &amp;amp; Technologies Used&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ansible – Configuration Management&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apache2 – Web Server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Linux (Debian-based OS)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;YAML – Automation language&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;📁 Project Directory Structure&lt;/strong&gt;&lt;br&gt;
sample_role/&lt;br&gt;
├── tasks/&lt;br&gt;
│   └── main.yml&lt;br&gt;
├── handlers/&lt;br&gt;
│   └── main.yml&lt;br&gt;
├── vars/&lt;br&gt;
│   └── main.yml&lt;br&gt;
├── files/&lt;br&gt;
│   └── index.html&lt;br&gt;
├── meta/&lt;br&gt;
└── README.md&lt;/p&gt;

&lt;p&gt;This structure follows the standard ansible-galaxy role layout.&lt;/p&gt;

&lt;p&gt;⚙️ Role Components Explained&lt;br&gt;
🔹 vars/main.yml&lt;/p&gt;

&lt;p&gt;Defines reusable variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
pkg: apache2
destfile: /var/www/html/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 tasks/main.yml&lt;/p&gt;

&lt;p&gt;Handles package installation and website deployment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: Install apache2
  package:
    name: "{{ pkg }}"
    state: latest
  when: ansible_os_family == "Debian"

- name: Deploy static website on apache2
  copy:
    src: "."
    dest: "{{ destfile }}"
  become: yes
  notify:
    - start apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 handlers/main.yml&lt;/p&gt;

&lt;p&gt;Ensures Apache service starts only when required:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: start apache2
  service:
    name: apache2
    state: started
    enabled: yes

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 files/&lt;/p&gt;

&lt;p&gt;Contains static website files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;Images
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvdr09bcipk1q33vs9o9a.png" alt=" " width="291" height="265"&gt;
These are copied directly to Apache’s web root directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;▶️ Playbook to Execute the Role&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hosts: all
become: yes
roles:

&lt;ul&gt;
&lt;li&gt;sample_role&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;🔄 Execution Flow&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Playbook calls the Ansible role&lt;/li&gt;
&lt;li&gt;Variables are loaded&lt;/li&gt;
&lt;li&gt;Apache is installed (Debian-based OS)&lt;/li&gt;
&lt;li&gt;Static website is deployed&lt;/li&gt;
&lt;li&gt;Handler is triggered&lt;/li&gt;
&lt;li&gt;Apache service starts and is enabled&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;✅ Expected Output&lt;/p&gt;

&lt;p&gt;Apache Web Server installed successfully&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkksydz2oofalgroqha1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkksydz2oofalgroqha1w.png" alt=" " width="800" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apache service running and enabled on boot&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmi3ptu7d31v3ewv44jw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmi3ptu7d31v3ewv44jw.png" alt=" " width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Static website accessible via browser using server IP&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F431m82arbi8wyetcqst7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F431m82arbi8wyetcqst7.png" alt=" " width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🌟 Benefits of Using Ansible Roles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reusable automation code&lt;/li&gt;
&lt;li&gt;Clean and organized structure&lt;/li&gt;
&lt;li&gt;Easy maintenance&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Faster deployments&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduced human errors&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🏁 Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This project demonstrates how Ansible Roles can be used to build scalable and reusable infrastructure automation.&lt;br&gt;
By separating tasks, handlers, variables, and files, the solution becomes production-ready and aligns with real-world DevOps practices.&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>devops</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
