How to hold Idempotence property of Ansible while restarting the HTTPD service?

- hosts: all
vars_prompt:
- name: "document_root"
prompt: "Enter your document root name"
private: no
- name: "http_portno"
prompt: "Enter the port no"
private: no
tasks:
- name: Install httpd software
package:
name: httpd
state: present
register: z
- name: Creating folder
file:
name: "{{ document_root }}"
state: directory
- name: Copy the configuration file
template:
dest: "etc/httpd/conf.d/https.conf"
src: "webs.conf"
when: z.rc==0
notify: Restart service
- name: Copy html code to document root
copy:
dest: "{{ document_root }}"
src: "web.html"
- name: Start httpd service
service:
name: "httpd"
state: started
enabled: yes
- firewalld:
port: "{{ http_portno }}/tcp"
state: enabled
permanent: yes
immediate: yes
handlers:
- name: Restart service
service:
name: "httpd"
state: restarted

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store