---
- name: (tor.yml) Ensure tor is installed.
  ansible.builtin.apt:
    name:
      - tor
    state: present
  when:
    - ansible_facts.os_family == "Debian"
  tags:
    - tor-service

- name: (tor.yml) Ensure tor servive is enabled and started
  ansible.builtin.service:
    name: tor
    enabled: true
    state: started
  tags:
    - tor-service

- name: (tor.yml) Adjust configuration /etc/tor/torrc using template torrc.j2
  ansible.builtin.template:
    src: etc/tor/torrc.j2
    dest: "{{ torrc_path }}"
    owner: root
    group: root
    mode: "0644"
  notify: "Restart tor service"
  when:
    - torrc_path is defined
  tags:
    - tor-service
