restart-vpn.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ---
  2. - hosts: 10.0.0.2
  3. become: true
  4. gather_facts: false
  5. vars_files:
  6. - "{{ inventory_dir }}/vars/vault.yaml"
  7. vars:
  8. openvpn_service: "openvpn@nord"
  9. openvpn_remotes: "{{ vaulted_openvpn_remotes }}"
  10. openvpn_user: "{{ vaulted_openvpn_user }}"
  11. openvpn_pass: "{{ vaulted_openvpn_pass }}"
  12. tasks:
  13. - name: Change Nord Endpoint
  14. ansible.builtin.shell:
  15. cmd: nordvpn connect
  16. - name: Query Nord Endpoint Info
  17. ansible.builtin.shell:
  18. cmd: "nordvpn status | grep Hostname | awk '{print $2}'"
  19. register: nord_status
  20. - name: "NordVPN Endpoint"
  21. debug:
  22. msg: "{{ nord_status.stdout }}"
  23. # - name: Select random NordVPN Endpoint
  24. # ansible.builtin.set_fact:
  25. # nord_endpoint: "{{ vaulted_openvpn_remotes | random }}"
  26. # - name: Set config from chosen endpoint "{{ nord_endpoint.cn }}"
  27. # ansible.builtin.set_fact:
  28. # nord_remote: "{{ nord_endpoint.remote }}"
  29. # nord_cn: "{{ nord_endpoint.cn }}"
  30. # - name: Update config file settings
  31. # ansible.builtin.lineinfile:
  32. # path: /etc/openvpn/nord.conf
  33. # regexp: "{{ item.regexp }}"
  34. # line: "{{ item.line }}"
  35. # loop:
  36. # - { "label": "remote", "regexp": "^remote ", "line": "remote {{ nord_remote }} 443" }
  37. # - { "label": "cn", "regexp": "^verify-x509-name", "line": "verify-x509-name CN={{ nord_cn }}" }
  38. # loop_control:
  39. # label: "{{ item.label }}"
  40. # - name: Update motd script with new endpoint
  41. # ansible.builtin.lineinfile:
  42. # path: /usr/local/bin/vpn-endpoint
  43. # regexp: "^endpoint="
  44. # line: "endpoint={{ nord_cn }}"
  45. # - name: Bounce {{ openvpn_service }} service
  46. # ansible.builtin.systemd_service:
  47. # name: "{{ openvpn_service }}"
  48. # state: restarted
  49. # - name: Bounce unbound service
  50. # ansible.builtin.systemd_service:
  51. # name: unbound
  52. # state: restarted