- name: install tor and required packages apt: name: - tor - tor-geoipdb - torsocks - proxychains state: present update_cache: yes - 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: yes 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' notify: restart tor - 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