Making httpd services non-idempotent

kanav Gupta
1 min readJan 16, 2021

--

Task Description:

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

Whenever we run ansible playbook without changing conf settings or some changes it will automatically start httpd services because we have given key value as restarted so it consumes more resources although we haven’t done any changes

So here to make these services not idempotence I am gonna use when keyword

Here is my ansible playbook code

- hosts: all
vars:
- dvd_dir: "/dvd1"

tasks:
- file:
state: directory
path: "{{ dvd_dir }}"
- mount:
src: "/dev/cdrom"
path: "{{ dvd_dir }}"
state: mounted
fstype: iso9660

- yum_repository:
baseurl: "{{ dvd_dir }}/AppStream"
name: "dvd1"
gpgcheck: no
description: "Yum repo 1"
- yum_repository:
baseurl: "{{ dvd_dir }}/BaseOS"
name: "dvd2"
gpgcheck: no
description: "Yum repo 2"
- package:
name: "httpd"
state: present
- copy:
dest: /var/www/html/index.html
register: result
- copy:
src: /home/kanav/t.conf
dest: /etc/httpd/conf.d
- service:
name: "httpd"
state: restarted
when: result.changed

At first execution attempt it restarts services because we are uploading conf file for first time

After first execution of playbook if we run playbook without any changes it will not restart services

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response