---
- name: "Save service state: {{ item }}"
  ansible.builtin.set_fact:
    bigboot_service_to_disable:
      service: "{{ ansible_facts['services'][item]['name'] }}"
      state: "{{ (ansible_facts['services'][item]['state'] == 'running') | ternary('started', 'stopped') }}"
      status: "{{ (ansible_facts['services'][item]['status'] == 'enabled') | ternary('true', 'false') }}"

- name: "Disable and stop service: {{ item }}"
  ansible.builtin.service:
    name: "{{ item }}"
    state: stopped
    enabled: false

- name: "Log disabled service state: {{ item }}"
  ansible.builtin.lineinfile:
    path: "{{ bigboot_disabled_services_log }}"
    line: "{{ item }},{{ bigboot_service_to_disable['state'] }},{{ bigboot_service_to_disable['status'] }}"
    create: true
    state: present
    owner: root
    group: root
    mode: "0600"
