-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate client configuration for OpenVPN and deploy to a secondary container to test the VPN client connection.
- Loading branch information
Showing
9 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
# Copyright 2017, Logan Vig <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
- name: Store CA key | ||
slurp: | ||
src: "{{ openvpn_key_path }}/ca.crt" | ||
register: ca_cert | ||
|
||
- name: Store tls-auth key | ||
slurp: | ||
src: "{{ openvpn_key_path }}/tls-auth.key" | ||
register: tls_auth_key | ||
|
||
- name: Store client certificates | ||
slurp: | ||
src: "{{ openvpn_key_path }}/{{ item }}.crt" | ||
register: client_certs | ||
with_items: "{{ openvpn_clients_generate }}" | ||
|
||
- name: Store client keys | ||
slurp: | ||
src: "{{ openvpn_key_path }}/{{ item }}.key" | ||
register: client_keys | ||
with_items: "{{ openvpn_clients_generate }}" | ||
|
||
- name: Generate client configurations | ||
template: | ||
src: client.ovpn.j2 | ||
dest: "{{ openvpn_clients_config_path }}/{{ item.0.item }}.ovpn" | ||
owner: root | ||
group: root | ||
mode: '0600' | ||
with_together: | ||
- "{{ client_certs.results }}" | ||
- "{{ client_keys.results }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# {{ ansible_managed }} | ||
|
||
{% set _ = openvpn_client_config.update(openvpn_client_config_overrides) %} | ||
|
||
{% for i in openvpn_client_config | dictsort %} | ||
{% set key = i.0 %} | ||
{% set param = i.1 %} | ||
{% if param is iterable and param is not string %} | ||
{# The key is a list so we output multiple config items with the same key #} | ||
{% for inner_param in param %} | ||
{{ key }} {{ inner_param }} | ||
{% endfor %} | ||
{% else %} | ||
{{ key }}{% if param != '' %} {{ param }}{% endif %} | ||
|
||
{% endif %} | ||
{% endfor %} | ||
|
||
<ca> | ||
{{ ca_cert.content | b64decode }} | ||
</ca> | ||
|
||
<tls-auth> | ||
{{ tls_auth_key.content | b64decode }} | ||
</tls-auth> | ||
|
||
<cert> | ||
{{ item.0.content | b64decode }} | ||
</cert> | ||
|
||
<key> | ||
{{ item.1.content | b64decode }} | ||
</key> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,5 +50,32 @@ | |
failed_when: openvpn_pid.rc != 0 | ||
register: openvpn_pid | ||
changed_when: false | ||
- name: Fetch the openvpn client configuration | ||
slurp: | ||
src: "{{ openvpn_key_path }}/{{ openvpn_clients[0] }}.ovpn" | ||
register: test_client_config | ||
- name: Set the ping test IP | ||
set_fact: | ||
test_ping_ip: "{{ openvpn_ipv4_network | ipaddr(1) | ipaddr('address') }}" | ||
vars_files: | ||
- test-vars.yml | ||
|
||
- name: Test the OpenVPN client connection | ||
hosts: openvpn_clients | ||
tasks: | ||
- name: Install OpenVPN in the client | ||
package: | ||
name: openvpn | ||
- name: Drop the client configuration | ||
copy: | ||
content: "{{ hostvars[groups['openvpn_servers'][0]].test_client_config.content | b64decode }}" | ||
dest: /etc/openvpn/client.conf | ||
- name: Start the OpenVPN client | ||
service: | ||
name: '[email protected]' | ||
state: restarted | ||
post_tasks: | ||
- name: Ping the OpenVPN server over the tunnel | ||
command: > | ||
ping -c4 {{ hostvars[groups['openvpn_servers'][0]].test_ping_ip }} | ||
changed_when: false |