Skip to content

Service Management

Service Control

# Basic service management
- name: Ensure service running
  service:
    name: nginx
    state: started
    enabled: yes

# Systemd specific
- name: Configure service
  systemd:
    name: myapp
    state: restarted
    daemon_reload: yes

Service Tasks

- name: Service handlers
  block:
    - name: Update config
      template:
        src: nginx.conf.j2
        dest: /etc/nginx/nginx.conf
      notify: restart nginx

  handlers:
    - name: restart nginx
      service:
        name: nginx
        state: restarted