Update jenkins slave user key file name
[infra/tools.git] / infra / openvpn_automation / generate-user-ovpn / tasks / main.yaml
1 ---
2 - name: Check {{ client_name }} key existence
3   stat:
4     path: "{{ nordix_openvpn_easyrsa_path }}/pki/private/{{ client_name }}.key"
5   register: client_privatekey
6   delegate_to: localhost
7
8 - name: Create client cert and csr
9   command: ./easyrsa --batch --req-cn={{ client_name }} gen-req {{ client_name }} nopass
10   args:
11     chdir: "{{ nordix_openvpn_easyrsa_path }}"
12   when: client_privatekey.stat.exists == false
13   delegate_to: localhost
14
15 - name: Copy client key to client_config directory
16   copy:
17     src: "{{ nordix_openvpn_easyrsa_path }}/pki/private/{{ client_name }}.key"
18     dest: "{{ nordix_openvpn_clientconfig }}/keys/"
19   changed_when: true
20   delegate_to: localhost
21
22 - name: Copy client csr to nordix CA
23   copy:
24     src: "{{ nordix_openvpn_easyrsa_path }}/pki/reqs/{{ client_name }}.req"
25     dest: /tmp
26   changed_when: true
27
28 - name: Check {{ client_name }} csr existence in CA
29   stat:
30     path: "{{ nordix_ca_easyrsa_path }}/pki/reqs/{{ client_name }}.req"
31   register: client_csr
32
33 - name: Import client csr
34   command: ./easyrsa --batch import-req /tmp/{{ client_name }}.req {{ client_name }}
35   args:
36     chdir: "{{ nordix_ca_easyrsa_path }}"
37   when: client_csr.stat.exists == false
38   changed_when: true
39
40 - name: Check {{ client_name }} crt existence in CA
41   stat:
42     path: "{{ nordix_ca_easyrsa_path }}/pki/issued/{{ client_name }}.crt"
43   register: client_crt
44
45 - name: Sign client csr
46   command: ./easyrsa --batch sign-req client {{ client_name }}
47   args:
48     chdir: "{{ nordix_ca_easyrsa_path }}"
49   when: client_crt.stat.exists == false
50   changed_when: true
51
52 - name: Fetch client cert to client-configs/keys/ dir
53   fetch:
54     src: "{{ nordix_ca_easyrsa_path }}/pki/issued/{{ client_name }}.crt"
55     dest: "{{ nordix_openvpn_clientconfig }}/keys/"
56     flat: true
57   changed_when: true
58
59 - name: Generate Client .ovpn file
60   script: make_config.sh "{{ client_name }}"
61   args:
62     chdir: "{{ nordix_openvpn_clientconfig }}/"
63     executable: /bin/bash
64   delegate_to: localhost
65
66 - name: Log user specific ovpn files location on the console
67   debug:
68     msg:
69       - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70       - "The ovpn file {{ client_name }}.ovpn is located in {{ nordix_openvpn_clientconfig }}/files/{{ client_name }}.ovpn"
71       - "Please share the newly generated {{ client_name }}.ovpn file with user over email with below instructions,"
72       - "1. Please install the openvpn on your laptop. Assuming you using Ubuntu:"
73       -     "#sudo apt install openvpn"
74       - "2. Then you need to open the VPN connection using the .ovpn file which contain all the required certificates:"
75       -     "#sudo openvpn --config {{ client_name }}.ovpn &"
76       - "3. Now, user should have access to all the VMs directly from your laptop"
77       - "4. In case you use Windows 10 OS, please use the community version of OpenVPN client:"
78       -     "https://swupdate.openvpn.org/community/releases/openvpn-install-2.4.8-I602-Win10.exe"
79       - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
80       - ''
81   delegate_to: localhost