-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added playbook for installation of VPN server
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*~ | ||
*.swp | ||
files/static.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
# This file was created by Ansible. | ||
# Manual changes will be lost. | ||
|
||
# Don't add masquerading rule if it is already exists | ||
iptables -n -t nat -L POSTROUTING | grep -q MASQUERADE && exit 0 ||: | ||
|
||
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This file was created by Ansible. | ||
# Manual changes will be lost. | ||
|
||
dev tun | ||
ifconfig {{ server_addr }} {{ client_addr }} | ||
secret {{ keyfile }} | ||
|
||
{% if compression is defined and compression %} | ||
comp-lzo | ||
|
||
{% endif %} | ||
keepalive {{ keepalive }} | ||
ping-timer-rem | ||
persist-tun | ||
persist-key | ||
|
||
up /usr/local/sbin/do_masquerade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
- hosts: vpn | ||
|
||
vars: | ||
server_addr: 10.8.0.1 | ||
client_addr: 10.8.0.2 | ||
keyfile: static.key | ||
keepalive: "10 60" | ||
compression: true | ||
|
||
tasks: | ||
- include: tasks/base.yml | ||
|
||
- name: install openvpn server | ||
apt: pkg=openvpn state=installed | ||
|
||
- name: create masquerading script | ||
copy: | ||
src=files/do_masquerade.sh | ||
dest=/usr/local/sbin/do_masquerade | ||
owner=root | ||
group=root | ||
mode=0755 | ||
|
||
- name: create openvpn config | ||
template: | ||
src=templates/openvpn.conf.j2 | ||
dest=/etc/openvpn/openvpn.conf | ||
backup=yes | ||
notify: | ||
- restart openvpn | ||
|
||
- name: manage openvpn key | ||
copy: | ||
src=files/{{ keyfile }} | ||
dest=/etc/openvpn/{{ keyfile }} | ||
owner=root | ||
group=root | ||
mode=0600 | ||
notify: | ||
- restart openvpn | ||
|
||
- name: enable ipv4 forwarding | ||
sysctl: name=net.ipv4.ip_forward value=1 | ||
|
||
- name: start openvpn server | ||
service: name=openvpn enabled=yes state=started | ||
|
||
handlers: | ||
- name: restart openvpn | ||
service: name=openvpn enabled=yes state=restarted |