Restarting HTTPD service is not idempotence in nature

Tejas Sanghai
3 min readMar 25, 2021

--

In general, idempotence is “the property of certain operations in mathematics and computer science that can be applied multiple times without changing the result beyond the initial application”. For Ansible it means after 1 run of a playbook to set things to a desired state, further runs of the same playbook should result in 0 changes. In simplest terms, idempotency means you can be sure of a consistent state in your environment.

Configuration Drift is where servers in an infrastructure become more and more different as time goes on. So the state of the machine deviates, or drifts, from the baseline due to manual changes and updates.

To help combat this configuration drift, two approaches can be taken. 1) Use an automated tool, such as Ansible, and run them frequently and repeatedly to keep machines in line 2) Rebuild machine instances frequently so they don’t have much time to drift from the baseline.

Removing or Minimizing Drift with Ansible

There are multiple ways to combat Configuration Drift with Ansible, such as using Ansible Tower to check frequently with playbooks that detect drift, then notify the appropriate resource through chat, email, etc and/or make an appropriate modification to keep it in line with the baseline.

Now Let us understand this idempotency with an example..

In this example I have written one playbook in YAML language. In this playbook I have added one task of copying the file and other httpd concepts like install httpd , restart httpd, etc.

Now, when i run this playbook in my control node we can see the following output, which is basically we are running this playbook for the very first time so we see some changes as ansible highlights the changes when it occurs.

In above image you can see that task of copying the file and restarting of httpd server gets highlighted but when we run this playbook for second time we get different output

So in above you image you can see ansible didn’t perform those task that are previously done.

As I have said earlier an idempotent operation is one that can be applied multiple times without changing the result beyond the initial application.

Thank You!!!!

--

--

No responses yet