# platform = multi_platform_all
# reboot = false
# strategy = disable
# complexity = low
# disruption = low
{{%- if init_system == "systemd" %}}
- name: Disable service {{{ SERVICENAME }}}
  block:
  - name: Gather the service facts
    service_facts:

  - name: Disable service {{{ SERVICENAME }}}
    systemd:
      name: "{{{ DAEMONNAME }}}.service"
      enabled: "no"
      state: "stopped"
{{%- if MASK_SERVICE %}}
      masked: "yes"
{{%- endif %}}
    when: '"{{{ DAEMONNAME }}}.service" in ansible_facts.services'

- name: "Unit Socket Exists - {{{ DAEMONNAME }}}.socket"
  command: systemctl list-unit-files {{{ DAEMONNAME }}}.socket
  args:
    warn: False
  register: socket_file_exists
  changed_when: False
  ignore_errors: True
  check_mode: False

- name: Disable socket {{{ SERVICENAME }}}
  systemd:
    name: "{{{ DAEMONNAME }}}.socket"
    enabled: "no"
    state: "stopped"
{{%- if MASK_SERVICE %}}
    masked: "yes"
{{%- endif %}}
  when: '"{{{ DAEMONNAME }}}.socket" in socket_file_exists.stdout_lines[1]'
{{% elif init_system == "upstart" %}}
- name: Stop {{{ SERVICENAME }}}
  command: /sbin/service '{{{ DAEMONNAME }}}' stop

- name: Switch off {{{ SERVICENAME }}}
  command: /sbin/chkconfig --level 0123456 '{{{ DAEMONNAME }}}' off
{{%- else %}}
JINJA TEMPLATE ERROR: Unknown init system '{{{ init_system }}}'
{{%- endif %}}
