Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible code to restart Apache

Tags:

ansible

I have a basic playbook to restart an Apache server but I'm wondering how the following command is interpreted and converted to its equivalent -- service httpd start.

- name: ensure apache is running
    service:
      name: httpd
      state: started
like image 985
user1050619 Avatar asked Apr 19 '26 16:04

user1050619


1 Answers

service module first gets the status of the service (httpd). If the service is started or running or reloaded and the desired service state is started, it will not restart the service.

self.svc_change = False
...
...
if not self.running and self.state in ["started", "running", "reloaded"]:
    self.svc_change = True

If you want to restart:

state: restarted   ==>  service httpd restart

service - Manage services

  • started/stopped are idempotent actions that will not run commands unless necessary
  • restarted will always bounce the service
  • reloaded will always reload
like image 112
helloV Avatar answered Apr 26 '26 16:04

helloV