Restarting HTTPD Service is not idempotence in nature and also consume more resources this is a way to rectify this challenge in Ansible playbook
Before moving to the main topic things to know
What is Ansible?
Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn’t depend on agent software and has no additional security infrastructure, so it’s easy to deploy.
What is Ansible Playbook?
Playbooks are the files where Ansible code is written. … Playbooks are one of the core features of Ansible and tell Ansible what to execute. They are like a to-do list for Ansible that contains a list of tasks. Playbooks contain the steps which the user wants to execute on a particular machine
Starting with My Practical demonstration..
I created a playbook named webserver.yml
In this playbook
STEP 1
I have added a group in the option given by host ,So that if in future I can add one more IP in inventory , I can easily choose to which group it should be fitted for our purpose .
Tasks
STEP 2
Installing Httpd package by using package module .
STEP 3
Copying the Web Page to the document root using copy module .
STEP 4
Starting the Httpd service ,using the service module and instead of using attribute restarted ,I am using started .
Because started attribute in service module is idempotence in nature.
STEP 5
Creating a firewall rule for the port no 80 running with protocol tcp.
After running the command
ansible-playbook webserver.yml
Here my website is running .
Thankyou .
For any queries or suggestions dm me .