2016-07-27 21:27:11 +00:00
|
|
|
---
|
|
|
|
|
2016-08-11 20:54:29 +00:00
|
|
|
- hosts: localhost
|
|
|
|
gather_facts: False
|
|
|
|
vars_files:
|
2016-08-16 03:32:44 +00:00
|
|
|
- config.cfg
|
2016-08-11 20:54:29 +00:00
|
|
|
vars_prompt:
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 20:54:29 +00:00
|
|
|
- name: "server_ip"
|
|
|
|
prompt: "\nEnter IP address of your server:\n"
|
|
|
|
private: no
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 20:54:29 +00:00
|
|
|
- name: "server_user"
|
|
|
|
prompt: "What user should we use to login on the server?:\n"
|
|
|
|
default: "root"
|
|
|
|
private: no
|
2016-08-18 08:16:22 +00:00
|
|
|
|
|
|
|
- name: "easyrsa_p12_export_password"
|
|
|
|
prompt: "Enter the password for p12 certificates:\n"
|
|
|
|
default: "vpn"
|
|
|
|
private: yes
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-08-11 20:54:29 +00:00
|
|
|
tasks:
|
|
|
|
- name: Add the server to the vpn-host group
|
2016-08-16 03:32:44 +00:00
|
|
|
add_host:
|
2016-08-11 20:54:29 +00:00
|
|
|
hostname: "{{ server_ip }}"
|
|
|
|
groupname: vpn-host
|
|
|
|
ansible_ssh_user: "{{ server_user }}"
|
|
|
|
ansible_python_interpreter: "/usr/bin/python2.7"
|
2016-08-18 08:16:22 +00:00
|
|
|
easyrsa_p12_export_password: "{{ easyrsa_p12_export_password }}"
|
2016-08-11 20:54:29 +00:00
|
|
|
|
|
|
|
- name: Wait for SSH to become available
|
|
|
|
local_action: "wait_for port=22 host={{ server_ip }} timeout=320"
|
2016-08-16 03:32:44 +00:00
|
|
|
become: false
|
2016-08-11 20:54:29 +00:00
|
|
|
|
2016-07-30 17:26:30 +00:00
|
|
|
- name: User management
|
2016-08-11 20:54:29 +00:00
|
|
|
hosts: vpn-host
|
2016-07-27 21:27:11 +00:00
|
|
|
gather_facts: false
|
2016-07-30 16:05:04 +00:00
|
|
|
become: true
|
2016-07-27 21:27:11 +00:00
|
|
|
vars_files:
|
2016-08-16 03:32:44 +00:00
|
|
|
- config.cfg
|
|
|
|
|
2016-07-27 21:27:11 +00:00
|
|
|
tasks:
|
|
|
|
- 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 }}"
|
|
|
|
|
|
|
|
- name: Build the client's p12
|
|
|
|
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-07-27 21:27:11 +00:00
|
|
|
- name: Get active users
|
|
|
|
shell: >
|
2016-07-27 21:29:39 +00:00
|
|
|
grep ^V pki/index.txt | grep -v "{{ server_name }}" | awk '{print $5}' | sed 's/\/CN=//g'
|
2016-07-27 21:27:11 +00:00
|
|
|
args:
|
|
|
|
chdir: '{{ easyrsa_dir }}/easyrsa3/'
|
|
|
|
register: valid_certs
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-07-27 21:27:11 +00:00
|
|
|
- name: Revoke non-existing users
|
|
|
|
shell: >
|
|
|
|
ipsec pki --signcrl --cacert {{ easyrsa_dir }}/easyrsa3//pki/ca.crt --cakey {{ easyrsa_dir }}/easyrsa3/pki/private/ca.key --reason superseded --cert {{ easyrsa_dir }}/easyrsa3//pki/issued/{{ item }}.crt > /etc/ipsec.d/crls/{{ item }}.der &&
|
|
|
|
./easyrsa revoke {{ item }} &&
|
|
|
|
ipsec rereadcrls
|
|
|
|
args:
|
|
|
|
chdir: '{{ easyrsa_dir }}/easyrsa3/'
|
|
|
|
when: item not in users
|
|
|
|
with_items: "{{ valid_certs.stdout_lines }}"
|
2016-08-16 03:32:44 +00:00
|
|
|
|
2016-07-27 21:27:11 +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-07-27 21:27:11 +00:00
|
|
|
- name: Build the mobileconfigs
|
2016-08-14 17:03:23 +00:00
|
|
|
template: src=roles/vpn/templates/mobileconfig.j2 dest=/{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item.0 }}.mobileconfig mode=0600
|
2016-07-27 21:27:11 +00:00
|
|
|
with_together:
|
|
|
|
- "{{ users }}"
|
|
|
|
- "{{ PayloadContent.results }}"
|
2016-08-16 03:32:44 +00:00
|
|
|
no_log: True
|
|
|
|
|
2016-07-27 21:27:11 +00:00
|
|
|
- name: Fetch users P12
|
|
|
|
fetch: src=/{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item }}.p12 dest=configs/{{ server_name }}_{{ item }}.p12 flat=yes
|
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
|
|
|
- name: Fetch users mobileconfig
|
|
|
|
fetch: src=/{{ easyrsa_dir }}/easyrsa3//pki/private/{{ item }}.mobileconfig dest=configs/{{ server_name }}_{{ item }}.mobileconfig flat=yes
|
|
|
|
with_items: "{{ users }}"
|
|
|
|
|
|
|
|
- name: Fetch server CA certificate
|
|
|
|
fetch: src=/{{ easyrsa_dir }}/easyrsa3/pki/ca.crt dest=configs/{{ server_name }}_ca.crt flat=yes
|