2018-08-27 14:05:45 +00:00
|
|
|
---
|
|
|
|
- name: Configure the server and install required software
|
|
|
|
hosts: vpn-host
|
|
|
|
gather_facts: false
|
|
|
|
become: true
|
|
|
|
vars_files:
|
|
|
|
- config.cfg
|
2019-04-08 20:20:34 +00:00
|
|
|
tasks:
|
|
|
|
- block:
|
2020-01-07 13:28:19 +00:00
|
|
|
- name: Wait until the cloud-init completed
|
|
|
|
wait_for:
|
|
|
|
path: /var/lib/cloud/data/result.json
|
|
|
|
delay: 10
|
|
|
|
timeout: 600
|
|
|
|
state: present
|
|
|
|
become: false
|
|
|
|
when: cloudinit
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- name: Ensure the config directory exists
|
|
|
|
file:
|
|
|
|
dest: "configs/{{ IP_subject_alt_name }}"
|
|
|
|
state: directory
|
|
|
|
mode: "0700"
|
|
|
|
|
|
|
|
- name: Dump the ssh config
|
|
|
|
copy:
|
|
|
|
dest: "configs/{{ IP_subject_alt_name }}/ssh_config"
|
|
|
|
mode: "0600"
|
|
|
|
content: |
|
2020-02-12 07:14:13 +00:00
|
|
|
Host {{ IP_subject_alt_name }} {{ algo_server_name }}
|
2020-01-07 13:28:19 +00:00
|
|
|
HostName {{ IP_subject_alt_name }}
|
|
|
|
User {{ ansible_ssh_user }}
|
|
|
|
Port {{ ansible_ssh_port }}
|
2020-02-12 06:58:20 +00:00
|
|
|
IdentityFile {{ SSH_keys.private | realpath }}
|
2020-01-07 13:28:19 +00:00
|
|
|
KeepAlive yes
|
|
|
|
ServerAliveInterval 30
|
2020-01-31 10:24:29 +00:00
|
|
|
when: inventory_hostname != 'localhost'
|
2020-01-07 13:28:19 +00:00
|
|
|
become: false
|
|
|
|
delegate_to: localhost
|
|
|
|
|
2019-04-08 20:20:34 +00:00
|
|
|
- import_role:
|
|
|
|
name: common
|
|
|
|
tags: common
|
2018-08-27 14:05:45 +00:00
|
|
|
|
2019-04-08 20:20:34 +00:00
|
|
|
- import_role:
|
2019-06-19 15:31:43 +00:00
|
|
|
name: dns
|
|
|
|
when:
|
|
|
|
- algo_dns_adblocking or
|
|
|
|
dns_encryption
|
|
|
|
tags: dns
|
2019-04-08 20:20:34 +00:00
|
|
|
|
|
|
|
- import_role:
|
|
|
|
name: wireguard
|
|
|
|
when: wireguard_enabled
|
|
|
|
tags: wireguard
|
|
|
|
|
|
|
|
- import_role:
|
|
|
|
name: strongswan
|
|
|
|
when: ipsec_enabled
|
|
|
|
tags: ipsec
|
|
|
|
|
|
|
|
- import_role:
|
|
|
|
name: ssh_tunneling
|
|
|
|
when: algo_ssh_tunneling
|
|
|
|
tags: ssh_tunneling
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- name: Dump the configuration
|
2019-04-26 15:48:28 +00:00
|
|
|
copy:
|
2019-04-08 20:20:34 +00:00
|
|
|
dest: "configs/{{ IP_subject_alt_name }}/.config.yml"
|
|
|
|
content: |
|
|
|
|
server: {{ 'localhost' if inventory_hostname == 'localhost' else inventory_hostname }}
|
|
|
|
server_user: {{ ansible_ssh_user }}
|
2020-01-07 13:28:19 +00:00
|
|
|
ansible_ssh_port: "{{ ansible_ssh_port|default(22) }}"
|
2019-04-08 20:20:34 +00:00
|
|
|
{% if algo_provider != "local" %}
|
2019-11-01 08:57:20 +00:00
|
|
|
ansible_ssh_private_key_file: {{ SSH_keys.private }}
|
2019-04-08 20:20:34 +00:00
|
|
|
{% endif %}
|
|
|
|
algo_provider: {{ algo_provider }}
|
|
|
|
algo_server_name: {{ algo_server_name }}
|
|
|
|
algo_ondemand_cellular: {{ algo_ondemand_cellular }}
|
|
|
|
algo_ondemand_wifi: {{ algo_ondemand_wifi }}
|
|
|
|
algo_ondemand_wifi_exclude: {{ algo_ondemand_wifi_exclude }}
|
2019-06-19 15:31:43 +00:00
|
|
|
algo_dns_adblocking: {{ algo_dns_adblocking }}
|
2019-04-08 20:20:34 +00:00
|
|
|
algo_ssh_tunneling: {{ algo_ssh_tunneling }}
|
2019-07-10 16:31:25 +00:00
|
|
|
algo_store_pki: {{ algo_store_pki }}
|
2019-04-08 20:20:34 +00:00
|
|
|
IP_subject_alt_name: {{ IP_subject_alt_name }}
|
|
|
|
ipsec_enabled: {{ ipsec_enabled }}
|
|
|
|
wireguard_enabled: {{ wireguard_enabled }}
|
2019-04-26 15:48:28 +00:00
|
|
|
{% if tests|default(false)|bool %}
|
2020-01-13 16:20:40 +00:00
|
|
|
ca_password: '{{ CA_password }}'
|
|
|
|
p12_password: '{{ p12_export_password }}'
|
2019-04-26 15:48:28 +00:00
|
|
|
{% endif %}
|
2019-04-08 20:20:34 +00:00
|
|
|
become: false
|
2019-04-26 15:48:28 +00:00
|
|
|
delegate_to: localhost
|
2018-08-27 14:05:45 +00:00
|
|
|
|
2019-04-08 20:20:34 +00:00
|
|
|
- name: Create a symlink if deploying to localhost
|
|
|
|
file:
|
|
|
|
src: "{{ IP_subject_alt_name }}"
|
|
|
|
dest: configs/localhost
|
|
|
|
state: link
|
|
|
|
force: true
|
|
|
|
when: inventory_hostname == 'localhost'
|
2018-08-30 12:36:35 +00:00
|
|
|
|
2019-07-10 16:31:25 +00:00
|
|
|
- name: Import tmpfs tasks
|
|
|
|
import_tasks: playbooks/tmpfs/umount.yml
|
|
|
|
become: false
|
|
|
|
delegate_to: localhost
|
|
|
|
vars:
|
|
|
|
facts: "{{ hostvars['localhost'] }}"
|
|
|
|
when:
|
|
|
|
- pki_in_tmpfs
|
|
|
|
- not algo_store_pki
|
|
|
|
|
2019-04-08 20:20:34 +00:00
|
|
|
- debug:
|
|
|
|
msg:
|
|
|
|
- "{{ congrats.common.split('\n') }}"
|
|
|
|
- " {{ congrats.p12_pass if algo_ssh_tunneling or ipsec_enabled else '' }}"
|
2019-07-10 16:31:25 +00:00
|
|
|
- " {{ congrats.ca_key_pass if algo_store_pki and ipsec_enabled else '' }}"
|
2019-04-08 20:20:34 +00:00
|
|
|
- " {{ congrats.ssh_access if algo_provider != 'local' else ''}}"
|
|
|
|
tags: always
|
2018-08-27 14:05:45 +00:00
|
|
|
rescue:
|
2019-04-08 20:20:34 +00:00
|
|
|
- include_tasks: playbooks/rescue.yml
|