Update ansible roles to automate nordix openvpn user management
[infra/tools.git] / infra / openvpn_automation / playbooks / roles / vpn-client-certs / tasks / main.yml
1 ---
2 - name: Check {{ user_name }} key existence
3   stat:
4     path: "{{ nordix_openvpn_easyrsa_path }}/pki/private/{{ user_name }}.key"
5   register: client_privatekey
6
7 - name: Create client cert and csr
8   command: ./easyrsa --batch --req-cn={{ user_name }} gen-req {{ user_name }} nopass
9   args:
10     chdir: "{{ nordix_openvpn_easyrsa_path }}"
11   when: client_privatekey.stat.exists == false
12
13 - name: Copy client key to client_config directory
14   copy:
15     src: "{{ nordix_openvpn_easyrsa_path }}/pki/private/{{ user_name }}.key"
16     dest: "{{ nordix_openvpn_clientconfig }}/keys/"
17     remote_src: true
18     owner: "infra"
19     group: "infra"
20   changed_when: true
21   become: true
22
23 - name: Fetch the CA, user {{ user_name }} cert and key
24   fetch:
25     src: "{{ nordix_openvpn_easyrsa_path }}/pki/reqs/{{ user_name }}.req"
26     dest: "{{ hostvars['localhost']['vpn_user_files_location'] }}/"
27     flat: true
28     remote_src: true
29     force: true
30   become: true