Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for service name and ensure started #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
vpn_gateway_service: strongswan
vpn_gateway_config_dir: "/etc/ipsec.d/{{ role_name }}"
vpn_gateway_configs: []
vpn_gateway_cacerts: []
vpn_gateway_default_config_params:
type: tunnel
keyingtries: 0
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: restart ipsec
service:
name: strongswan
name: "{{ vpn_gateway_service }}"
state: restarted

- name: reload ipsec
Expand Down
14 changes: 13 additions & 1 deletion tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@
owner: root
group: root
mode: 0600
notify: reload ipsec
notify: restart ipsec

- name: Copy ca certs
copy:
content: "{{ item.content }}"
dest: "/etc/ipsec.d/cacerts/{{ item.name }}"
owner: root
group: root
mode: 0644
with_items: "{{ vpn_gateway_cacerts }}"
loop_control:
label: "{{ item.name }}"
notify: restart ipsec
3 changes: 2 additions & 1 deletion tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

- name: IPSec must be running
service:
name: strongswan
name: "{{ vpn_gateway_service }}"
state: started
enabled: yes
4 changes: 3 additions & 1 deletion tasks/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
assert:
that: item.psk | length > 0
fail_msg: "Variable 'psk' is not correct for vpn_gateway_configs with name: {{ item.name }}"
when: (item.state | default('present')) == 'present'
when:
- (item.state | default('present')) == 'present'
- item.private_key is not defined
loop: "{{ vpn_gateway_configs }}"
2 changes: 2 additions & 0 deletions templates/ipsec.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# {{ connection.left }} -> {{ connection.right }}
conn {{ connection.name }}
{% for param_key in connection %}
{% if param_key != 'name' %}
{{ param_key }}={{ connection[param_key] }}
{% endif %}
{% endfor %}
{% endfor %}
5 changes: 5 additions & 0 deletions templates/ipsec.secrets.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

{% for config in vpn_gateway_configs %}
{% if (config.state | default('present')) == 'present' %}
{% if config.psk is defined %}
{{ config.local.public }} {{ config.remote.public }} : PSK {{ config.psk }}
{% endif %}
{% if config.private_key is defined %}
: RSA {{ config.private_key }}
{% endif %}
{% endif %}
{% endfor %}