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

update openvpn #11

Merged
merged 1 commit into from
Jun 21, 2024
Merged
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: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace: bodsch
name: core

version: 2.0.0
version: 2.1.0

readme: README.md

Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/dns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/linked_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/parse_checksum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/python.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/union_by.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/filter/verify.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/lookup/file_glob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/cache/cache_valid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/checksum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/diff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/directory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/dns_lookup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/lists.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/module_results.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/template/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/aur.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/easyrsa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2022, Bodo Schulz <bodo@boone-schulz.de>
Expand Down Expand Up @@ -116,7 +116,8 @@ def run(self):
"""
args.append("--batch")
# args.append(f"--pki-dir={self._pki_dir}")
args.append(f"--req-cn={self._req_cn_ca}")
if self._req_cn_ca:
args.append(f"--req-cn={self._req_cn_ca}")
args.append(self.state)
args.append(self._req_cn_server)
args.append("nopass")
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/facts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/journalctl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/mysql_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/openvpn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2022, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/openvpn_client_certificate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2022, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/openvpn_crl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2022-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/openvpn_ovpn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2022, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/openvpn_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/package_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/pip_requirements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/remove_ansible_backups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/sync_directory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2023, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/syslog_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# (c) 2020-2022, Bodo Schulz <bodo@boone-schulz.de>
Expand Down
1 change: 1 addition & 0 deletions roles/openvpn/collections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

collections:
- name: bodsch.core
- name: community.crypto
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ openvpn_persistent_pool:
- name: roadrunner_one
state: present
static_ip: 10.8.3.10
netmask: 255.255.0.0
- name: roadrunner_two
state: present
static_ip: 10.8.3.11
- name: molecule
state: present
static_ip: 10.8.3.100
- name: obsolate
state: absent
static_ip: 10.8.3.250


openvpn_mobile_clients:
- name: roadrunner_one
Expand Down
4 changes: 2 additions & 2 deletions roles/openvpn/tasks/configure/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
- name: create or revoke client certificate
delegate_to: "{{ client.remote }}"
bodsch.core.openvpn_client_certificate:
state: "{{ client.state | default('present') }}"
state: "{{ client.state }}"
username: "{{ client.name }}"
args:
chdir: '{{ openvpn_easyrsa.directory }}'
Expand All @@ -56,7 +56,7 @@
loop_control:
index_var: index
loop_var: client
label: "{{ client.name }}, state: {{ client.state | default('present') }}"
label: "{{ client.name }}, state: {{ client.state }}"

- name: create openvpn client configs
ansible.builtin.include_tasks: configure/static_client_instances.yml
Expand Down
27 changes: 27 additions & 0 deletions roles/openvpn/tasks/configure/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@
- openvpn_persistent_pool is defined
- openvpn_persistent_pool | count > 0

- name: remove old static client IPs
ansible.builtin.file:
state: absent
path: "/etc/openvpn/client/{{ item.name }}"
loop:
"{{ openvpn_persistent_pool }}"
loop_control:
label: "{{ item.name | default('') }}"
when:
- openvpn_persistent_pool is defined
- openvpn_persistent_pool | count > 0
- item.state | default('present') == 'absent'

- name: define static client IPs
ansible.builtin.template:
src: openvpn/server/static-client.j2
dest: "/etc/openvpn/client/{{ item.name }}"
mode: 0644
loop:
"{{ openvpn_persistent_pool }}"
loop_control:
label: "{{ item.name | default('') }}"
when:
- openvpn_persistent_pool is defined
- openvpn_persistent_pool | count > 0
- item.state | default('present') == 'present'

- name: create link for openrc init
ansible.builtin.file:
src: "{{ openvpn_directory }}/server/server.conf"
Expand Down
6 changes: 6 additions & 0 deletions roles/openvpn/tasks/configure/static_client_instances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
when:
- not _client_checksum.stat.exists or not certificate_equal
block:
- name: create export directory
ansible.builtin.file:
state: directory
path: /root/vpn-configs
mode: 0700

- name: create export directory
ansible.builtin.file:
state: directory
Expand Down
2 changes: 1 addition & 1 deletion roles/openvpn/templates/openvpn/server/ipp.txt.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
opp.static_ip | string | length > 0 or
(opp.static_ip | ansible.utils.ipv4 or
opp.static_ip | ansible.utils.ipv6) %}
{{ opp.name }},{{ opp.static_ip }},
{{ opp.name }},{{ opp.static_ip }}
{% endif %}
{% endfor %}
11 changes: 8 additions & 3 deletions roles/openvpn/templates/openvpn/server/server.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ topology subnet
openvpn_subnet.netmask | string | length > 0 %}
server {{ openvpn_subnet.ip }} {{ openvpn_subnet.netmask }}

ifconfig-pool-persist ipp.txt
{% if openvpn_persistent_pool is defined and
openvpn_persistent_pool | count > 0 %}
# ifconfig-pool-persist {{ openvpn_directory }}/ipp.txt 30
client-config-dir {{ openvpn_directory }}/client
{% endif %}

{% else %}
# NO SERVER NETWORK HAS BEEN DEFINED!
{% endif %}
Expand Down Expand Up @@ -78,8 +83,8 @@ push "rcvbuf {{ _push_rcvbuf }}"
{% endif %}
{% endif %}

sndbuf 393216
rcvbuf 393216
## sndbuf 393216
## rcvbuf 393216

{% if openvpn_mtu is defined and
openvpn_mtu | string | length > 0 %}
Expand Down
1 change: 1 addition & 0 deletions roles/openvpn/templates/openvpn/server/static-client.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ifconfig-push {{ item.static_ip }} {{ item.netmask | default('255.255.255.0') }}
1 change: 1 addition & 0 deletions roles/openvpn/vars/archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openvpn_dependencies:
- procps-ng
- rsync
- sshpass
- python-jinja

openvpn_packages:
- openvpn
Expand Down