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