2 # tasks file for vpn_server
3 - name: Update the system packages
7 - name: Install Python, Openvpn & Easy-rsa
16 - name: Remove CA directory
19 path: "{{ openvpn_ca }}"
21 - name: Create CA directory
22 command: make-cadir "{{ openvpn_ca }}"
25 - name: Customize CA variable configuration
28 dest: "{{ openvpn_ca }}/vars"
32 - name: Create keys directory under {{ openvpn_ca }}
34 path: "{{ openvpn_ca }}/keys"
37 - name: Build Diffie-Hellman parameters and key generation
40 sh "{{ openvpn_ca }}"/clean-all;
41 sh "{{ openvpn_ca }}"/build-dh;
42 openvpn --genkey --secret keys/ta.key;
44 chdir: "{{ openvpn_ca }}"
48 - name: Copy key and certificates
50 src: "{{ hostvars['localhost']['vpn_files_location'] }}/{{ item }}"
51 dest: "{{ openvpn_ca }}/keys"
53 - "{{ openvpn_server }}.crt"
54 - "{{ openvpn_server }}.key"
57 - name: Copy key and certificates to /etc/openvpn
59 src: "{{ hostvars['localhost']['vpn_files_location'] }}/{{ item }}"
62 - "{{ openvpn_server }}.crt"
63 - "{{ openvpn_server }}.key"
66 - name: Copy DH cert and key to /etc/openvpn
68 src: "{{ openvpn_ca }}/keys/{{ item }}"
75 - name: Adjust OpenVPN Server Configuration
78 dest: "/etc/openvpn/server.conf"
81 - name: Configuration IP forwarding
83 name: net.ipv4.ip_forward
88 - name: Updating iptables for incoming
94 - name: Updating iptables for outgoing
100 - name: Setup the MASQUERADE
102 path: /lib/systemd/system/openvpn@.service
103 insertafter: 'ExecStart='
104 line: "ExecStartPost=/sbin/iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -d {{ network_cidr }}/24 -j MASQUERADE"
106 - name: Systemd to reread configuration
110 - name: Start and Enable Openvpn Service
117 - name: Cleanup vpn files in localhost
119 path: "{{ hostvars['localhost']['vpn_files_location'] }}"
121 delegate_to: localhost