Creating ansible-playbook for setting up custom apache webserver.

Task is to set up custom apache webserver using ansible-playbook
Document root of apache webserver is /var/www/html, but we can change it.
And for any changes we need to make changes in configuration file. Configuration file of apache webserver is /etc/httpd/conf.d/.
To change our document root need to make a file inside /etc/httpd/conf.d/ with file extension .conf, and inside the file we have to mention the port and Document root whatever we want.
Now lets start!
- In lw.conf file

2. yml code:


3. When we ran playbook for first time it should change and should show yellow color notification of changed.

And yes shows yellow colored notification of changed.
If ran the same playbook again it should not show yellow , because service is already restarted, but because restarting service dont show idempotency in ansible it shows change again.
So we will solve this issue using handlers.
What are handler?
Sometimes you want a task to run only when a change is made on a machine. For example, you may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses handlers to address this use case. Handlers are tasks that only run when notified. Each handler should have a globally unique name.
Adding handler code:

also, add notify command after copying configuration file

now changed a port in conf file and ran playbook it should show change, because we changed the port.

Now if run the same playbook again it should not show change because nothing is changed.

Shows green color notification that means no change.
Here is the web page !!!

Here we completed our task of setting up httpd and solving issue with restarting service!!
Hope you like it!!
keep learning!!!!
THANK YOU