⚜ CONFIGURATION OF APACHE WEBSERVER USING ANSIBLE ⚜

🔰 What is Ansible?

⭐ Let’s Begin….. ⭐

♦️ Task Description:-
◾Restarting HTTPD Service is not idempotence in nature and also consume more resources.. Suggest a way to rectify this challenge in Ansible Playbook.

⭐ In Controller Node,

👉🏻 Variable File :

port_no: "8080"
dvd_dir: "/dvd1"
doc_root: "/var/www/first"

👉🏻 Ansible Play Book :

- hosts: <ip of webserver>
vars_files:
- vars.yml
tasks:- name: "Creating Directory For Mounting"
file:
state: directory
path: "{{ dvd_dir }}"
- name: "Mounting...."
mount:
src: "/dev/cdrom"
fstype: iso9660
state: mounted
path: "{{ dvd_dir }}"
- name: "Yum repo AppStream"
yum_repository:
name: "dvd1"
description: "AppStream"
baseurl: "{{ dvd_dir }}/AppStream"
gpgcheck: no
- name: "Yum repo BaseOS"
yum_repository:
name: "dvd2"
description: "BaseOS"
baseurl: "{{ dvd_dir }}/BaseOS"
gpgcheck: no
- name: "Install httpd"
package:
name: "httpd"
state: present
- name: "Start httpd services"
service:
name: "httpd"
state: started
- name: "Copying Configuration File"
template:
src: "/root/ansible-ws/httpd/httpc.conf"
dest: "/etc/httpd/conf.d/httpc.conf"
notify: Restart Service
- name: "Enabling Firewall"
firewalld:
port: "{{ port_no }}/tcp"
state: enabled
permanent: yes
immediate: yes
- name: "New Document Root Directory"
file:
state: directory
path: "{{ doc_root }}"
- name: "Copying content to document Root"
copy:
content: "TASK 11.3 COMPLETED SUCCESSFULLY"
dest: "{{ doc_root }}/index.html"

👉🏻 Configuration file of webserver :

#Configuration file of webserver#Listen {{ port_no }}<virtualhost {{ ansible_facts['default_ipv4']['address'] }}:{{ port_no }}>
DocumentRoot {{ doc_root }}
</virtualhost>

👉🏻 Answer :

Adding Handlers to Play Book

          ***********************************
#Adding Handlers#
handlers:
- name: "Restart Service"
service:
name: "httpd"
state: restarted
***********************************

👉🏻 Now running Play-Book :

ansible-playbook -v <playbook_name>

👉🏻 Let’s Check in Target Node :

  1. Configuration File is copied
  2. Content is written in configuration file
  3. Changed the Document root from “/var/www/html” to “/var/www/first”
  4. Works on port no. 8080

👉🏻 Let’s Check on Browser !!!

⭐ My GitHub URL for this task:-

Thanks for Reading !! 🙌🏻😁📃

🔰 Keep Learning !! Keep Sharing !! 🔰

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vrukshali Torawane

DevOps Engineer • Terraform Certified • 2x RedHat Certified • DevOps Technical Writer✍🏻 • she/her • Learner Forever