aboutsummaryrefslogtreecommitdiff
path: root/roles/tor/tasks/tor_install.yaml
blob: f1fc92f44913a8d976513bd88141ae8f03e59d43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
- name: install tor and required packages
  apt:
    name:
      - tor
      - tor-geoipdb
      - torsocks
      - proxychains
      - curl
      - netcat-openbsd
    state: present
    update_cache: true
    cache_valid_time: 86400

- name: check if /etc/tor/torrc exists
  stat:
    path: /etc/tor/torrc
  register: torrc_stat

- name: back up /etc/tor/torrc
  copy:
    src: /etc/tor/torrc
    dest: /etc/tor/torrc.bak
    remote_src: true
    force: no
  when:
    - torrc_stat.stat.exists

- name: deploy custom tor configuration
  template:
    src: templates/torrc.j2
    dest: /etc/tor/torrc
    owner: debian-tor
    group: debian-tor
    mode: '0644'

- name: restart tor
  systemd:
    name: tor
    state: restarted
    enabled: true
  when: ansible_service_mgr == 'systemd'

- name: check if tor is routing traffic correctly
  command: curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip
  register: tor_check
  changed_when: false

- name: print tor check json response
  debug:
    msg: "tor check response: {{ tor_check.stdout }}"

- name: verify tor is active
  fail:
    msg: "tor is not routing traffic correctly: istor is {{ tor_check.stdout | from_json | json_query('IsTor') }}"
  when:
    - tor_check.stdout | from_json | json_query('IsTor') != true