Task 11.3

Mdkneema
2 min readMar 19, 2021

--

Restarting HTTPD Service is not idempotence in nature and also consume more resources suggest a way to rectify this challenge in Ansible playbook.

Description of the playbook-

  1. Creating directory /dvd1/
  2. mounting iso that contains all the software to dvd1 for configuring yum.
  3. configuring yum repository (AppStream).
  4. configuring yum repository (BaseOS)
  5. installing package httpd.
  6. creating document root location(folder).
  7. copying httpd configuration file into the location /etc/httpd/conf.d/web.conf.
  8. copying html files in document root directory.
  9. enabling firewall for required port.
  10. starting the service(httpd).
code page 1 (before idempotent)
code page 2 before idempotent

Configuration file (here, web.conf) for httpd

Issue in the following code-

Every time when the code will run, each time the service will restart and After executing the code, the most time consuming part is starting the service.

In the above case, the code is not idempotent in nature. to make the code Idempotent, we can either use handlers or when keyword. Using the when keyword in this kind of scenario will make the above code idempotent in nature.

The changes need to take place if anything related to the configuration file or html pages changes, only then restart the service again.

Code after service module’s restarted state starts acting idempotent after using when keyword

The changes are done only in 3 modules — template (temp variable), copy (cpy variable) and service (temp.changed == true or cpy.changed == true)

The above line means the module will execute only of there is any change in configuration file or html pages.

Execution of the code-

--

--

Mdkneema
Mdkneema

No responses yet