Luke Cyca 11 gadus atpakaļ
vecāks
revīzija
2da3df9cd1
3 mainītis faili ar 45 papildinājumiem un 23 dzēšanām
  1. 28
    23
      roles/vpn/tasks/openvpn.yml
  2. 16
    0
      roles/vpn/templates/client.cnf.j2
  3. 1
    0
      vars/defaults.yml

+ 28
- 23
roles/vpn/tasks/openvpn.yml Parādīt failu

@@ -17,10 +17,14 @@
17 17
     - ca
18 18
     - server
19 19
 
20
+- name: Create directories for clients
21
+  file: path={{ openvpn_path}}/{{ item }} state=directory
22
+  with_items: openvpn_clients
23
+
20 24
 - name: Generate RSA keys for the clients
21
-  command: openssl genrsa -out {{ item }}.key {{ openvpn_key_size }}
22
-           chdir={{ openvpn_path }}
23
-           creates={{ item }}.key
25
+  command: openssl genrsa -out client.key {{ openvpn_key_size }}
26
+           chdir={{ openvpn_path }}/{{ item }}
27
+           creates=client.key
24 28
   with_items: openvpn_clients
25 29
 
26 30
 - name: Set the proper permissions on all RSA keys
@@ -64,15 +68,20 @@
64 68
            creates=server.crt
65 69
 
66 70
 - name: Generate CSRs for the clients
67
-  command: openssl req -new -key {{ item }}.key -out {{ item }}.csr -subj "{{ openssl_request_subject }}/CN={{ item }}" 
68
-           chdir={{ openvpn_path }}
69
-           creates={{ item }}.csr
71
+  command: openssl req -new -key client.key -out client.csr -subj "{{ openssl_request_subject }}/CN={{ item }}"
72
+           chdir={{ openvpn_path }}/{{ item }}
73
+           creates=client.csr
70 74
   with_items: openvpn_clients
71 75
 
72 76
 - name: Generate certificates for the clients
73
-  command: openssl x509 -CA {{ openvpn_ca }}.crt -CAkey {{ openvpn_ca }}.key -CAcreateserial -req -days {{ openvpn_days_valid }} -in {{ item }}.csr -out {{ item }}.crt
74
-           chdir={{ openvpn_path }}
75
-           creates={{ item }}.crt
77
+  command: openssl x509 -CA {{ openvpn_ca }}.crt -CAkey {{ openvpn_ca }}.key -CAcreateserial -req -days {{ openvpn_days_valid }} -in client.csr -out client.crt
78
+           chdir={{ openvpn_path }}/{{ item }}
79
+           creates=client.crt
80
+  with_items: openvpn_clients
81
+
82
+- name: Create the client configs
83
+  template: src=client.cnf.j2
84
+            dest={{ openvpn_path }}/{{ item }}/{{ openvpn_server }}.ovpn
76 85
   with_items: openvpn_clients
77 86
 
78 87
 - name: Generate HMAC firewall key
@@ -109,22 +118,18 @@
109 118
   copy: src=etc_dnsmasq.conf dest=/etc/dnsmasq.conf
110 119
   notify: restart dnsmasq
111 120
 
112
-- name: Retrieve the ca.crt and ta.key files that clients will need in order to connect to the OpenVPN server
113
-  fetch: src={{ openvpn_path }}/{{ item }}
114
-         dest=/tmp/sovereign-openvpn-files
115
-  with_items:
116
-    - ca.crt
117
-    - ta.key
121
+- name: Copy the ca.crt and ta.key files that clients will need in order to connect to the OpenVPN server
122
+  command: cp {{ openvpn_path }}/{{ item[1] }} {{ openvpn_path }}/{{ item[0] }}
123
+  with_nested:
124
+    - openvpn_clients
125
+    - ["ca.crt", "ta.key"]
118 126
 
119
-- name: Retrieve the certificates that clients will need in order to connect to the OpenVPN server
120
-  fetch: src={{ openvpn_path }}/{{ item }}.crt
127
+- name: Retrieve the files that clients will need in order to connect to the OpenVPN server
128
+  fetch: src={{ openvpn_path }}/{{ item[0] }}/{{ item[1] }}
121 129
          dest=/tmp/sovereign-openvpn-files
122
-  with_items: openvpn_clients
123
-
124
-- name: Retrieve the keys that clients will need in order to connect to the OpenVPN server
125
-  fetch: src={{ openvpn_path }}/{{ item }}.key
126
-         dest=/tmp/sovereign-openvpn-files
127
-  with_items: openvpn_clients
130
+  with_nested:
131
+    - openvpn_clients
132
+    - ["client.crt", "client.key", "ca.crt", "ta.key", "{{ openvpn_server }}.ovpn"]
128 133
 
129 134
 - pause: seconds=5
130 135
          prompt="You are ready to set up your OpenVPN clients. The files that you need are in /tmp/sovereign-openvpn-files. Make sure LZO compression is enabled and that you provide the ta.key file for the TLS-Auth option with a direction of '1'. Press any key to continue..."

+ 16
- 0
roles/vpn/templates/client.cnf.j2 Parādīt failu

@@ -0,0 +1,16 @@
1
+client
2
+dev tun
3
+proto udp
4
+remote {{ openvpn_server }} 1194
5
+resolv-retry infinite
6
+nobind
7
+persist-key
8
+persist-tun
9
+
10
+ca ca.crt
11
+cert client.crt
12
+key client.key
13
+ns-cert-type server
14
+tls-auth ta.key 1
15
+comp-lzo
16
+verb 3

+ 1
- 0
vars/defaults.yml Parādīt failu

@@ -51,6 +51,7 @@ openvpn_path: "/etc/openvpn"
51 51
 openvpn_ca: "{{ openvpn_path }}/ca"
52 52
 openvpn_dhparam: "{{ openvpn_path }}/dh{{ openvpn_key_size }}.pem"
53 53
 openvpn_hmac_firewall: "{{ openvpn_path }}/ta.key"
54
+openvpn_server: "{{ domain }}"
54 55
 # openvpn_clients: (required)
55 56
 
56 57
 # webmail

Notiek ielāde…
Atcelt
Saglabāt