Browse Source

* Update OpenVPN role to generate self-contained "unified" .ovpn

  profiles

  * The role now generates .ovpn profiles with embedded CA, certificate,
    key, and HMAC firewall key information. These .ovpn profiles are
    compatible with OpenVPN for iOS and Android, and only a single file
    needs to be transferred to your mobile device.

  * Added explicit route information to the .ovpn profile
Joshua Lund 10 years ago
parent
commit
64883159e9
2 changed files with 49 additions and 12 deletions
  1. 30
    5
      roles/vpn/tasks/openvpn.yml
  2. 19
    7
      roles/vpn/templates/client.cnf.j2

+ 30
- 5
roles/vpn/tasks/openvpn.yml View File

@@ -79,15 +79,40 @@
79 79
            creates=client.crt
80 80
   with_items: openvpn_clients
81 81
 
82
-- name: Create the client configs
83
-  template: src=client.cnf.j2
84
-            dest={{ openvpn_path }}/{{ item }}/{{ openvpn_server }}.ovpn
85
-  with_items: openvpn_clients
86
-
87 82
 - name: Generate HMAC firewall key
88 83
   command: openvpn --genkey --secret {{ openvpn_hmac_firewall }}
89 84
            creates={{ openvpn_hmac_firewall }}
90 85
 
86
+- name: Register CA certificate contents
87
+  command: cat ca.crt
88
+           chdir={{ openvpn_path }}
89
+  register: openvpn_ca_contents
90
+
91
+- name: Register client certificate contents
92
+  command: cat client.crt
93
+           chdir={{ openvpn_path }}/{{ item }}
94
+  with_items: openvpn_clients
95
+  register: openvpn_client_certificates
96
+
97
+- name: Register client key contents
98
+  command: cat client.key
99
+           chdir={{ openvpn_path }}/{{ item }}
100
+  with_items: openvpn_clients
101
+  register: openvpn_client_keys
102
+
103
+- name: Register HMAC firewall contents
104
+  command: cat ta.key
105
+           chdir={{ openvpn_path }}
106
+  register: openvpn_hmac_firewall_contents
107
+
108
+- name: Create the client configs
109
+  template: src=client.cnf.j2
110
+            dest={{ openvpn_path }}/{{ item[0] }}/{{ openvpn_server }}.ovpn
111
+  with_together:
112
+    - openvpn_clients
113
+    - openvpn_client_certificates.results
114
+    - openvpn_client_keys.results
115
+
91 116
 - name: Generate Diffie-Hellman parameters (this will take a while)
92 117
   command: openssl dhparam -out {{ openvpn_dhparam }} {{ openvpn_key_size }}
93 118
            creates={{ openvpn_dhparam }}

+ 19
- 7
roles/vpn/templates/client.cnf.j2 View File

@@ -8,15 +8,27 @@ resolv-retry infinite
8 8
 nobind
9 9
 persist-key
10 10
 persist-tun
11
-
12
-ca ca.crt
13
-cert client.crt
14
-key client.key
15 11
 ns-cert-type server
16
-tls-auth ta.key 1
12
+comp-lzo
13
+key-direction 1
14
+verb 3
15
+route {{ ansible_default_ipv4.address }} 255.255.255.255 net_gateway
17 16
 
18 17
 # If you'd like to enable 2FA support, uncomment the following line
19 18
 ;auth-user-pass
20 19
 
21
-comp-lzo
22
-verb 3
20
+<ca>
21
+{{ openvpn_ca_contents.stdout }}
22
+</ca>
23
+
24
+<cert>
25
+{{ item[1].stdout }}
26
+</cert>
27
+
28
+<key>
29
+{{ item[2].stdout }}
30
+</key>
31
+
32
+<tls-auth>
33
+{{ openvpn_hmac_firewall_contents.stdout }}
34
+</tls-auth>

Loading…
Cancel
Save