Skip to content

Commit

Permalink
added playbook for installation of VPN server
Browse files Browse the repository at this point in the history
  • Loading branch information
timurb committed Oct 27, 2013
1 parent 7e48a2f commit ecd0bb4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
*.swp
files/static.key
9 changes: 9 additions & 0 deletions files/do_masquerade.sh
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
17 changes: 17 additions & 0 deletions templates/openvpn.conf.j2
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
51 changes: 51 additions & 0 deletions vpn.yml
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

0 comments on commit ecd0bb4

Please sign in to comment.