Pārlūkot izejas kodu

Generate a config file for each client generated

 * Add an openvpn_server variable
 * Move ${openvpn_client}.{key,csr,crt} to
   ${openvpn_client}/client.{key,csr,crt}
 * Generate ${openvpn_client}/${openvpn_server}.ovpn config file
 * Copy over a self contained directory of file per client that can be
   imported by networkmanager in ubuntu or run directly with `sudo
   openvpn ${openvpn_server}.ovpn
Ben Ford 10 gadus atpakaļ
vecāks
revīzija
588582aa25
4 mainītis faili ar 47 papildinājumiem un 23 dzēšanām
  1. 29
    23
      roles/vpn/tasks/openvpn.yml
  2. 16
    0
      roles/vpn/templates/client.cnf.j2
  3. 1
    0
      vars/defaults.yml
  4. 1
    0
      vars/user.yml

+ 29
- 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,21 @@
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 -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 -in client.csr -out client.crt
78
+           chdir={{ openvpn_path }}/{{ item }}
79
+           creates=client.crt
80
+  with_items: openvpn_clients
81
+
82
+
83
+- name: Create the client configs
84
+  template: src=client.cnf.j2
85
+            dest={{ openvpn_path }}/{{ item }}/{{ openvpn_server }}.ovpn
76 86
   with_items: openvpn_clients
77 87
 
78 88
 - name: Generate HMAC firewall key
@@ -112,21 +122,17 @@
112 122
   copy: src=etc_dnsmasq.conf dest=/etc/dnsmasq.conf
113 123
   notify: restart dnsmasq
114 124
 
115
-- name: Retrieve the ca.crt and ta.key files that clients will need in order to connect to the OpenVPN server
116
-  fetch: src={{ openvpn_path }}/{{ item }}
117
-         dest=/tmp/sovereign-openvpn-files
118
-  with_items:
119
-    - ca.crt
120
-    - ta.key
121
-
122
-- name: Retrieve the certificates that clients will need in order to connect to the OpenVPN server
123
-  fetch: src={{ openvpn_path }}/{{ item }}.crt
124
-         dest=/tmp/sovereign-openvpn-files
125
-  with_items: openvpn_clients
125
+- name: Copy the ca.crt and ta.key files that clients will need in order to connect to the OpenVPN server
126
+  command: cp {{ openvpn_path }}/{{ item[1] }} {{ openvpn_path }}/{{ item[0] }} 
127
+  with_nested:
128
+    - openvpn_clients
129
+    - ["ca.crt", "ta.key"]
126 130
 
127
-- name: Retrieve the keys that clients will need in order to connect to the OpenVPN server
128
-  fetch: src={{ openvpn_path }}/{{ item }}.key
131
+- name: Retrieve the files that clients will need in order to connect to the OpenVPN server
132
+  fetch: src={{ openvpn_path }}/{{ item[0] }}/{{ item[1] }}
129 133
          dest=/tmp/sovereign-openvpn-files
130
-  with_items: openvpn_clients
134
+  with_nested:
135
+    - openvpn_clients
136
+    - ["client.crt", "client.key", "client.config", "ca.crt", "ta.key"]
131 137
 
132 138
 - pause: 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

@@ -78,6 +78,7 @@ openvpn_clients:
78 78
   - laptop
79 79
   - phone
80 80
   - tablet
81
+openvpn_server: acme.com
81 82
 
82 83
 # # webmail
83 84
 # webmail_domain: TODO.com

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

@@ -78,6 +78,7 @@
78 78
 #   - laptop
79 79
 #   - phone
80 80
 #   - tablet
81
+# openvpn_server: acme.com
81 82
 
82 83
 # # webmail
83 84
 # webmail_domain: TODO.com

Notiek ielāde…
Atcelt
Saglabāt