In this article, I am going to show you how to configure the HTTPD ( Apache webserver)
how to change the document root of HTTPD .. and Restarting HTTPD Service is not idempotence in nature so how to solve this challenge with the help of Ansible playbook.
Here is my ansible-playbook...
- hosts: 192.168.43.251
vars:
Port_No: "8080"
dvd_dir: "/dvd1"
doc_root: "/var/www/first"
tasks:
- name: "Create mount point dir for cdrom"
file:
state: directory
path: "{{ dvd_dir }}"
- name:
mount:
src: "/dev/cdrom"
path: "{{dvd_dir}}"
state: mounted
fstype: "iso9660"
- name: AppStream Repo
yum_repository:
name: AppStream
description: AppStream Repo
baseurl: "{{ dvd_dir }}/AppStream"
gpgcheck: no
- name: BaseOS Repo
yum_repository:
name: "BaseOS"
description: "BaseOS Repo"
baseurl: "{{ dvd_dir }}/BaseOS"
gpgcheck: no
- name: Installing httpd
package :
name: httpd
state: present
- name: "Copying contents"
copy:
content: "TASK 11.3 SUCCESSFULY COMPLETED"
dest: "{{ doc_root }}/index.html"
- name: "Copying Configuration File"
template:
src: "/root/ansible/new.conf"
dest: "/etc/httpd/conf.d/new.conf"
- name: "Service Started"
service :
name: httpd
state: restarted
- name: "Firewall"
firewalld:
port: "{{ Port_No }}/tcp"
state: enabled
permanent: yes
immediate: yes
- name: "New Document Root Directory"
file:
state: directory
path: "{{ doc_root }}"
Here is my configuration file (new.conf)
Implementation:-
Target Node:-
configuration file changed
document root changed
working on port no 8080
web file copied (index.html)
Here you can see that the apache web server is configured successfully. But the problem is, I want that the service will be restarted only if there is some change/update in the configuration of that service, if the configuration is not changed then I don't want to restart the service. So to solve this issue I am going to use handlers
What are Handlers?
Handlers are the same as the other tasks in the playbook. It will run only if the task is notified...
Now I am going to run the playbook
Now here You can see that it is now showing an idempotence nature
Now let's check it once through the browser ...
It's working
So here my task is completed...
Comentários