Make HTTPD Service idempotence in Nature using Ansible
Anand Kumar
| Ansible | OpenShift | Terraform| DevOps | Hybrid Multi-Cloud | K8S & Docker | Software Engineer at Infinite Computer Solution
ARTH - Task 11.3.
Task Description:
?? 11.3 Restarting HTTPD Service is not idempotence in nature and also consume more resources to suggest a way to rectify this challenge in Ansible playbook.
Let's solve this problem by performing some task:
- Create an Ansible playbook to configure yum in the managed node.
- Install apache webserver httpd in the managed node.
- Configure the webserver.
Ansible Configuration File
#vim /etc/ansible/ansible.cfg
In the above ansible.cfg file mention, the path of the inventory file and also mention that host key checking is false.
Ansible inventory file:-
The Ansible inventory file defines the hosts and groups of hosts upon which commands, modules, and tasks in a playbook operate. The file can be in one of many formats depending on your Ansible environment and plugins. ... If necessary, you can also create project-specific inventory files in alternate locations.
Now check the connectivity with Target Node using the command
# ansible all -m ping
Create a configuration file for httpd
Here I have created a configuration file named httpd.conf
and the variable stored in the http_var.yml file
Create an Ansible Playbook:
In this playbook, we have configured yum, installed httpd, and configured it.
Now run the playbook
# ansible-playbook httpd_yum.yum
Here you can see the playbook run successfully.
- let's check yum is configured or not, we can check that using the command
# yum repolist
now you can see that it is configured successfully.
- check httpd is installed or not, we can check that using command
# rpm -q httpd
Now you can see it is installed successfully.
- check whether the configuration file is placed in target node or not.
Here you can see httpd.conf that we created is placed and configured successfully.