How to retain Idempotency in Ansible while restarting HTTPD Service?

Venky
2 min readDec 16, 2020

--

Challenging statement:

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

  • Whenever there is a change in the configuration file of httpd we have to restart the httpd service.
  • So for this, we will write the restart keyword in our ansible playbook but there is a problem — if we didn't change anything in the conf file also the httpd service will restart.
  • To solve this challenge we have to use the Handlers concept from Ansible.

HANDLERS:

  • We want to restart the httpd service only when there is a change in a configuration file.
  • If there is no change then we have to skip(shouldn't run) the restart of httpd service.
  • For this, we have the handler module in Ansible.

Let's jump into our practical

  • Configuration file for httpd
  • Now we have to write a webpage for our apache server.
  • Now it’s time to run the playbook
ansible-playbook playbook.yml
  • The first time it will run all the tasks because we changed our httpd configuration file
  • Now let us run the playbook again, now there is no change in the configuration file so httpd service shouldn't restart
    Let's check?
  • Here the restart task doesn't run!!!!!!!!

GITHUB REPO:

  • Thank you everyone for reading!

--

--

No responses yet