Add ansible role to configure openvpn
[infra/tools.git] / infra / configure_openvpn_client / playbooks / roles / vpn-client / tasks / main.yml
1 ---
2 # tasks file for vpn_client
3 - name: Create Directory for Client Config Files
4   file:
5     path: "{{ openvpn_ca }}/client_configs/{{ item }}"
6     state: directory
7     recurse: true
8   with_items:
9     - files
10     - keys
11
12 - name: Copy Client Sample Config file
13   template:
14     src: base.conf.j2
15     dest: "{{ openvpn_ca }}/client_configs/base.conf"
16     force: true
17
18 - name: Client certs and keys to client_configs
19   copy:
20     src: "{{ item }}"
21     dest: "{{ openvpn_ca }}/client_configs/keys"
22   with_items:
23     - "{{ hostvars['localhost']['vpn_user_files_location'] }}/{{ user_name }}.crt"
24     - "{{ hostvars['localhost']['vpn_user_files_location'] }}/{{ user_name }}.key"
25
26 - name: Copy ta & Client certs and keys to client_configs
27   copy:
28     remote_src: true
29     src: "{{ item }}"
30     dest: "{{ openvpn_ca }}/client_configs/keys"
31   with_items:
32     - "/etc/openvpn/ta.key"
33     - "/etc/openvpn/ca.crt"
34
35 - name: Create Client .ovpn file
36   script: make_config.sh "{{ user_name }}"
37   args:
38     chdir: "{{ openvpn_ca }}/client_configs/"
39     executable: /bin/bash
40
41 - name: Fetch Client .ovpn file
42   fetch:
43     src: "{{ openvpn_ca }}/client_configs/files/{{ item|basename }}"
44     dest: "{{ hostvars['localhost']['vpn_user_files_location'] }}/"
45     flat: true
46   with_items:
47     - "{{ user_name }}.ovpn"
48
49 - name: Start and Enable Openvpn Service
50   systemd:
51     name: openvpn@server
52     state: restarted
53     daemon_reload: true
54     enabled: true
55
56 - name: Log  user specific ovpn files location on the console
57   debug:
58     msg:
59       - +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
60       - zone specific user ovpn files are located in {{ hostvars['localhost']['vpn_user_files_location'] }}
61       - +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
62       - ''