Created
June 1, 2024 11:46
-
-
Save offlinehacker/a8259f7ab87a920e64eed2e00fc19b09 to your computer and use it in GitHub Desktop.
Ansible fetch protovpn servers (I don't use anymore)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
tasks: | |
- name: get protonvpn servers | |
ansible.builtin.uri: | |
url: https://api.protonmail.ch/vpn/logicals | |
register: protonvpn_servers | |
- name: filter protonvpn profiles | |
set_fact: | |
# filter protonvpn servers by taking json response, filter using jmespath and extract unique values | |
profile: "{{ protonvpn_servers.json | community.general.json_query(query) | unique }}" | |
# query for debugging | |
condition: "{{ query }}" | |
vars: | |
# construct country filter by prefixing with `ExitCountry == ` and joining with || | |
country_filter: "{{ ['ExitCountry == `'] | product(item.value.countries) | map('join') | list | join('` || ') }}`" | |
# min and max tier filters | |
tier_filter: "Tier >= `{{item.value.min_tier | default(1)}}` && Tier <= `{{item.value.max_tier | default(5)}}`" | |
# if secure_core is set filter only nodes where entry and exit nodes are not in same country | |
entry_exit_filter: '{{ "&& " + ("EntryCountry != ExitCountry" if item.value.secure_core else "EntryCountry == ExitCountry") if "secure_core" in item.value else "" }}' | |
# if tor is set filter nodes that have `tor` in domain name | |
tor_filter: '{{ "&& " + ("" if item.value.tor else "!") + "contains(Domain, `tor`)" if "tor" in item.value else "" }}' | |
# finaly filter and query | |
filter: "({{country_filter}}) && {{tier_filter}} {{entry_exit_filter}} {{tor_filter}} && Status == `1` && contains(Domain, 'protonvpn')" | |
# apply filter, sorty by score, reverse with high score first and construct new dict with domain and entry ips | |
query: "reverse(sort_by(LogicalServers[?{{filter}}], &Score))[*].{Domain: Domain, IP: Servers[0].EntryIP}" | |
profiles: | |
eu: | |
min_tier: 2 | |
max_tier: 2 | |
secure_core: true | |
tor: false | |
countries: | |
- NL | |
- BG | |
- AT | |
- DE | |
- CH | |
si: | |
min_tier: 2 | |
max_tier: 2 | |
tor: false | |
countries: | |
- SI | |
with_dict: "{{ profiles }}" | |
register: protonvpn_server_profiles | |
- name: protonvpn ips | |
set_fact: | |
protonvpn_ips: "{{ protonvpn_server_profiles | community.general.json_query(query) | unique }}" | |
vars: | |
query: "results[].ansible_facts.profile[].IP" | |
- name: print protonvpn ips | |
debug: | |
var: protonvpn_ips | |
- name: print protonvpn profiles | |
debug: | |
var: protonvpn_server_profiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment