algo/vpn.yml

138 lines
4.7 KiB
YAML
Raw Normal View History

2016-07-11 16:09:14 +00:00
---
2016-05-31 00:45:34 +00:00
- name: Install StrongSwan
hosts: vpn-host
gather_facts: false
remote_user: root
2016-07-11 21:51:31 +00:00
vars_files:
- config.cfg
2016-05-31 00:45:34 +00:00
2016-05-15 15:06:03 +00:00
tasks:
2016-05-31 00:45:34 +00:00
- name: Wait for port 22 to become available
local_action: "wait_for port=22 host={{ inventory_hostname }}"
2016-07-12 07:10:50 +00:00
#- name: Updating apt-get
#raw: apt-get update -qq
2016-05-31 00:45:34 +00:00
2016-07-12 07:10:50 +00:00
#- name: Install python2.7 for Ansible
#raw: apt-get install -qq -y python2.7
2016-05-31 00:45:34 +00:00
2016-07-12 07:10:50 +00:00
#- name: Install StrongSwan
#apt: name=strongswan state=latest update_cache=yes
2016-05-15 15:06:03 +00:00
2016-07-12 07:10:50 +00:00
#- name: Enable strongswan
#service: name=strongswan enabled=yes
2016-05-15 15:06:03 +00:00
2016-07-12 07:10:50 +00:00
#- name: Enable packet forwarding for IPv4
#sysctl: name=net.ipv4.ip_forward value=1
2016-05-15 15:06:03 +00:00
2016-07-12 07:10:50 +00:00
#- name: Do not accept ICMP redirects (prevent MITM attacks)
#sysctl: name=net.ipv4.conf.all.accept_redirects value=0
2016-05-15 15:06:03 +00:00
2016-07-12 07:10:50 +00:00
#- name: Do not send ICMP redirects (we are not a router)
#sysctl: name=net.ipv4.conf.all.send_redirects value=0
2016-05-15 16:12:17 +00:00
2016-07-12 07:10:50 +00:00
#- name: Configure iptables so IPSec traffic can traverse the tunnel
#iptables: table=nat chain=POSTROUTING source=10.0.0.0/24 jump=MASQUERADE
2016-05-15 16:12:17 +00:00
2016-07-12 07:00:46 +00:00
- name: Setup the ipsec.conf file from our template
template: src=ipsec.conf.j2 dest=/etc/ipsec.conf owner=root group=root mode=644
notify:
- restart strongswan
2016-05-15 16:12:17 +00:00
2016-07-12 07:00:46 +00:00
- name: Setup the ipsec.secrets file with users and passwords
template: src=ipsec.secrets.j2 dest=/etc/ipsec.secrets owner=root group=root mode=600
notify:
- restart strongswan
2016-07-11 21:51:31 +00:00
2016-07-12 07:00:46 +00:00
- name: Install git
apt: name=git state=latest
2016-07-11 21:51:31 +00:00
2016-07-12 07:20:08 +00:00
#- name: Fetch easy-rsa-ipsec repo
#git: repo=git://github.com/ValdikSS/easy-rsa-ipsec.git dest="{{ easyrsa_dir }}"
2016-07-11 21:51:31 +00:00
- name: Setup the vars file from our template
template: src=easy-rsa.vars.j2 dest={{ easyrsa_dir }}/easyrsa3/vars
- name: Ensure the pki directory is not exist
file: dest={{ easyrsa_dir }}/easyrsa3/pki state=absent
when: easyrsa_reinit_existent == True
- name: Build the pki enviroments
shell: |
./easyrsa init-pki
touch '{{ easyrsa_dir }}/easyrsa3/pki/pki_initialized'
args:
chdir: '{{ easyrsa_dir }}/easyrsa3/'
creates: '{{ easyrsa_dir }}/easyrsa3/pki/pki_initialized'
- name: Build the CA pair
shell: |
./easyrsa build-ca nopass
touch {{ easyrsa_dir }}/easyrsa3/pki/ca_initialized
args:
chdir: '{{ easyrsa_dir }}/easyrsa3/'
creates: '{{ easyrsa_dir }}/easyrsa3/pki/ca_initialized'
notify:
- restart strongswan
- name: Build the server pair
shell: |
2016-07-12 18:05:06 +00:00
./easyrsa --subject-alt-name=DNS:{{ server_name }},IP:{{ server_ip }} build-server-full {{ server_name }} nopass
2016-07-11 21:51:31 +00:00
touch '{{ easyrsa_dir }}/easyrsa3/pki/server_initialized'
args:
chdir: '{{ easyrsa_dir }}/easyrsa3/'
creates: '{{ easyrsa_dir }}/easyrsa3/pki/server_initialized'
notify:
- restart strongswan
- name: Build the client's pair
shell: |
2016-07-12 18:05:06 +00:00
./easyrsa --subject-alt-name=DNS:{{ server_name }},IP:{{ server_ip }} build-client-full {{ item }} nopass
2016-07-11 21:51:31 +00:00
touch '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_initialized'
args:
chdir: '{{ easyrsa_dir }}/easyrsa3/'
creates: '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_initialized'
with_items: "{{ users }}"
- name: Build the client's p12
shell: |
2016-07-12 18:05:06 +00:00
openssl pkcs12 -in {{ easyrsa_dir }}/easyrsa3//pki/issued/{{ item }}.crt -inkey {{ easyrsa_dir }}/easyrsa3//pki/private/{{ item }}.key -export -name {{ item }} -out /{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item }}.p12 -certfile {{ easyrsa_dir }}/easyrsa3//pki/ca.crt -passout pass:vpn
2016-07-11 21:51:31 +00:00
touch '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_p12_initialized'
args:
chdir: '{{ easyrsa_dir }}/easyrsa3/'
creates: '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_p12_initialized'
with_items: "{{ users }}"
- name: Make the CA cert to the strongswan directory
copy: remote_src=True src='{{ easyrsa_dir }}/easyrsa3/pki/ca.crt' dest=/etc/ipsec.d/cacerts/ca.crt owner=root group=root mode=0600
notify:
- restart strongswan
- name: Make the server cert to the strongswan directory
copy: remote_src=True src='{{ easyrsa_dir }}/easyrsa3/pki/issued/{{ server_name }}.crt' dest=/etc/ipsec.d/certs/{{ server_name }}.crt owner=root group=root mode=0600
notify:
- restart strongswan
- name: Make the server key to the strongswan directory
copy: remote_src=True src='{{ easyrsa_dir }}/easyrsa3/pki/private/{{ server_name }}.key' dest=/etc/ipsec.d/private/{{ server_name }}.key owner=root group=root mode=0600
notify:
- restart strongswan
- name: restart strongswan
service: name=strongswan state=restarted
handlers:
- name: restart strongswan
service: name=strongswan state=restarted