2016-08-18 09:32:28 +00:00
|
|
|
- name: Gather Facts
|
|
|
|
setup:
|
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Install StrongSwan
|
|
|
|
apt: name=strongswan state=latest update_cache=yes
|
|
|
|
|
|
|
|
- name: Enforcing ipsec with apparmor
|
|
|
|
shell: aa-enforce "{{ item }}"
|
|
|
|
with_items:
|
|
|
|
- /usr/lib/ipsec/charon
|
|
|
|
- /usr/lib/ipsec/lookip
|
|
|
|
- /usr/lib/ipsec/stroke
|
|
|
|
notify:
|
|
|
|
- restart apparmor
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Enable services
|
|
|
|
service: name={{ item }} enabled=yes
|
|
|
|
with_items:
|
|
|
|
- apparmor
|
|
|
|
- strongswan
|
|
|
|
- netfilter-persistent
|
|
|
|
|
|
|
|
- name: Configure iptables so IPSec traffic can traverse the tunnel
|
|
|
|
iptables: table=nat chain=POSTROUTING source="{{ vpn_network }}" jump=MASQUERADE
|
|
|
|
notify:
|
|
|
|
- save iptables
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Configure ip6tables so IPSec traffic can traverse the tunnel
|
|
|
|
iptables: ip_version=ipv6 table=nat chain=POSTROUTING source="{{ vpn_network_ipv6 }}" jump=MASQUERADE
|
|
|
|
notify:
|
2016-08-16 03:32:44 +00:00
|
|
|
- save iptables
|
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Setup the ipsec.conf file from our template
|
2016-08-16 03:32:44 +00:00
|
|
|
template: src=ipsec.conf.j2 dest=/etc/ipsec.conf owner=root group=root mode=0644
|
2016-08-11 08:54:34 +00:00
|
|
|
notify:
|
2016-08-16 03:32:44 +00:00
|
|
|
- restart strongswan
|
2016-08-11 08:54:34 +00:00
|
|
|
|
|
|
|
- name: Setup the ipsec.secrets file
|
2016-08-16 03:32:44 +00:00
|
|
|
template: src=ipsec.secrets.j2 dest=/etc/ipsec.secrets owner=root group=root mode=0600
|
2016-08-11 08:54:34 +00:00
|
|
|
notify:
|
2016-08-16 03:32:44 +00:00
|
|
|
- restart strongswan
|
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Fetch easy-rsa-ipsec from git
|
2016-08-16 03:32:44 +00:00
|
|
|
git: repo=git://github.com/ValdikSS/easy-rsa-ipsec.git version=ed4de10d7ce0726357fb1bb4729f8eb440c06e2b dest="{{ easyrsa_dir }}"
|
2016-08-11 08:54:34 +00:00
|
|
|
|
|
|
|
- name: Setup the vars file from our template
|
|
|
|
template: src=easy-rsa.vars.j2 dest={{ easyrsa_dir }}/easyrsa3/vars
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Ensure the pki directory is not exist
|
|
|
|
file: dest={{ easyrsa_dir }}/easyrsa3/pki state=absent
|
|
|
|
when: easyrsa_reinit_existent == True
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- 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'
|
|
|
|
|
2016-08-16 03:32:44 +00:00
|
|
|
- name: Build the CA pair
|
2016-08-11 08:54:34 +00:00
|
|
|
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:
|
2016-08-16 03:32:44 +00:00
|
|
|
- restart strongswan
|
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Build the server pair
|
|
|
|
shell: >
|
2016-08-18 09:44:34 +00:00
|
|
|
./easyrsa --subject-alt-name='DNS:{{ IP_subject_alt_name }},IP:{{ IP_subject_alt_name }}' build-server-full {{ IP_subject_alt_name }} nopass&&
|
2016-08-11 08:54:34 +00:00
|
|
|
touch '{{ easyrsa_dir }}/easyrsa3/pki/server_initialized'
|
|
|
|
args:
|
|
|
|
chdir: '{{ easyrsa_dir }}/easyrsa3/'
|
|
|
|
creates: '{{ easyrsa_dir }}/easyrsa3/pki/server_initialized'
|
|
|
|
notify:
|
2016-08-16 03:32:44 +00:00
|
|
|
- restart strongswan
|
2016-08-11 08:54:34 +00:00
|
|
|
|
|
|
|
- name: Build the client's pair
|
|
|
|
shell: >
|
|
|
|
./easyrsa build-client-full {{ item }} nopass &&
|
|
|
|
touch '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_initialized'
|
|
|
|
args:
|
|
|
|
chdir: '{{ easyrsa_dir }}/easyrsa3/'
|
|
|
|
creates: '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_initialized'
|
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
2016-08-16 03:32:44 +00:00
|
|
|
- name: Build the client's p12
|
2016-08-11 08:54:34 +00:00
|
|
|
shell: >
|
|
|
|
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:{{ easyrsa_p12_export_password }} &&
|
|
|
|
touch '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_p12_initialized'
|
|
|
|
args:
|
|
|
|
chdir: '{{ easyrsa_dir }}/easyrsa3/'
|
|
|
|
creates: '{{ easyrsa_dir }}/easyrsa3/pki/{{ item }}_p12_initialized'
|
|
|
|
with_items: "{{ users }}"
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Copy 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: Copy the server cert to the strongswan directory
|
2016-08-18 09:17:46 +00:00
|
|
|
copy: remote_src=True src='{{ easyrsa_dir }}/easyrsa3/pki/issued/{{ IP_subject_alt_name }}.crt' dest=/etc/ipsec.d/certs/{{ IP_subject_alt_name }}.crt owner=root group=root mode=0600
|
2016-08-11 08:54:34 +00:00
|
|
|
notify:
|
2016-08-16 03:32:44 +00:00
|
|
|
- restart strongswan
|
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Copy the server key to the strongswan directory
|
2016-08-18 09:17:46 +00:00
|
|
|
copy: remote_src=True src='{{ easyrsa_dir }}/easyrsa3/pki/private/{{ IP_subject_alt_name }}.key' dest=/etc/ipsec.d/private/{{ IP_subject_alt_name }}.key owner=root group=root mode=0600
|
2016-08-11 08:54:34 +00:00
|
|
|
notify:
|
2016-08-16 03:32:44 +00:00
|
|
|
- restart strongswan
|
2016-08-11 08:54:34 +00:00
|
|
|
|
|
|
|
- name: Register p12 PayloadContent
|
|
|
|
shell: >
|
|
|
|
cat /{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item }}.p12 | base64
|
|
|
|
register: PayloadContent
|
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
|
|
|
- name: Register CA PayloadContent
|
|
|
|
shell: >
|
|
|
|
cat /{{ easyrsa_dir }}/easyrsa3/pki/ca.crt | base64
|
|
|
|
register: PayloadContentCA
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Build the mobileconfigs
|
|
|
|
template: src=mobileconfig.j2 dest=/{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item.0 }}.mobileconfig mode=0600
|
|
|
|
with_together:
|
|
|
|
- "{{ users }}"
|
|
|
|
- "{{ PayloadContent.results }}"
|
2016-08-16 03:32:44 +00:00
|
|
|
no_log: True
|
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Fetch users P12
|
2016-08-18 09:36:54 +00:00
|
|
|
fetch: src=/{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item }}.p12 dest=configs/{{ IP_subject_alt_name }}_{{ item }}.p12 flat=yes
|
2016-08-11 08:54:34 +00:00
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
|
|
|
- name: Fetch users mobileconfig
|
2016-08-18 09:36:54 +00:00
|
|
|
fetch: src=/{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item }}.mobileconfig dest=configs/{{ IP_subject_alt_name }}_{{ item }}.mobileconfig flat=yes
|
2016-08-11 08:54:34 +00:00
|
|
|
with_items: "{{ users }}"
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 08:54:34 +00:00
|
|
|
- name: Fetch server CA certificate
|
2016-08-18 09:36:54 +00:00
|
|
|
fetch: src=/{{ easyrsa_dir }}/easyrsa3/pki/ca.crt dest=configs/{{ IP_subject_alt_name }}_ca.crt flat=yes
|
2016-08-11 08:54:34 +00:00
|
|
|
notify:
|
|
|
|
- congrats
|