#####################################
### someone's ansible provisioner ###
#####################################
# 2017 by someone <someone@somenet.org>
#
---
- name: install tor
  apt:
    pkg:
    - tor
    state: present
    policy_rc_d: 101
  when: setup_tor | bool
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: copy torrc
  copy:
    src: "{{item}}"
    dest: "/etc/tor/torrc"
    mode: 0600
    owner: "debian-tor"
    group: "debian-tor"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/torrc"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/torrc"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/torrc"
    - "default/torrc"
  when: setup_tor | bool
  notify: restart tor.service


# for each hidserv do a with first found.
- include_tasks: configure-hidserv.yml
  with_items: "{{hidden_services}}"
  loop_control:
    loop_var: hs
  when: setup_tor | bool


- name: enable and start tor.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: tor.service
  when: setup_tor | bool
