-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(wireguard): add role * fix(docker_compose): show project name in debug messages * chore(deps): update dependencies
- Loading branch information
Showing
21 changed files
with
641 additions
and
265 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ lock: | |
|
||
update: | ||
poetry up --latest | ||
poetry run galaxy-update requirements.yml | ||
|
||
checks: pc lint-py | ||
|
||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -6,10 +6,13 @@ authors = ["DeadNews <[email protected]>"] | |
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
ansible-core = "^2.16.5" | ||
ansible-core = "^2.17.1" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
galaxy-update = "^0.0.1a0" | ||
|
||
[tool.poetry.group.lint.dependencies] | ||
ansible-lint = { version = "^24.6.0", markers = "platform_system != 'Windows'" } | ||
ansible-lint = { version = "^24.6.1", markers = "platform_system != 'Windows'" } | ||
mypy = "^1.10.0" | ||
poethepoet = "^0.26.1" | ||
ruff = "^0.4.9" | ||
|
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
--- | ||
collections: | ||
- name: community.general | ||
version: 9.0.1 | ||
|
||
version: 9.1.0 | ||
- name: community.docker | ||
version: 3.10.3 | ||
version: 3.10.4 | ||
- name: ansible.posix | ||
version: 1.5.4 |
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,20 @@ | ||
# deadnews.util.wireguard | ||
|
||
> Setup Wireguard | ||
## Role Variables | ||
|
||
- [meta/argument_specs.yml](./meta/argument_specs.yml) | ||
- [vars/main.yml](./vars/main.yml) | ||
|
||
## Example Playbook | ||
|
||
- [molecule/wireguard/converge.yml](./molecule/wireguard/converge.yml) | ||
|
||
```yaml | ||
- hosts: servers | ||
roles: | ||
- role: deadnews.util.wireguard | ||
wireguard_interface: wg0 | ||
wireguard_template: templates/wg0.conf.j2 | ||
``` |
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,5 @@ | ||
--- | ||
- name: (Handler) Restart Wireguard service | ||
ansible.builtin.systemd: | ||
name: wg-quick@{{ wireguard_interface }}.service | ||
state: restarted |
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,20 @@ | ||
--- | ||
argument_specs: | ||
main: | ||
short_description: The main entry point for the wireguard role. | ||
options: | ||
wireguard_interface: | ||
description: The Wireguard interface name. | ||
type: str | ||
|
||
wireguard_template: | ||
description: The Wireguard configuration template. | ||
type: str | ||
|
||
wireguard_ip_forward: | ||
description: Enable and persist ip forwarding. | ||
type: bool | ||
|
||
wireguard_debug: | ||
description: Display debug information after deployment. | ||
type: bool |
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,6 @@ | ||
--- | ||
galaxy_info: | ||
author: DeadNews | ||
description: Setup Wireguard | ||
license: MIT | ||
min_ansible_version: 2.16.0 |
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,35 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
become: true | ||
vars: | ||
wireguard_host: 127.0.0.1 | ||
wireguard_privatekey_host: IKJPGZNOcrbIh1QU8yJ6oaXsSyUoQp8QUhm1uvfp5Vo= # gitleaks:allow | ||
wireguard_privatekey_peer: EKgPYhHgk1kqIkR+kFCvU8+N+yiLwqDkjcl0cy1vs2Y= # gitleaks:allow | ||
wireguard_publickey_host: 7I3L6nZ0P3K6TmWzJUe3xQjk/gTyoNaCwe1oDHpfGGI= # gitleaks:allow | ||
wireguard_publickey_peer: iEuV0dLE9OYfZzoKYrHZBK6Hzr/8dn1aovDuUrt9/g8= # gitleaks:allow | ||
|
||
tasks: | ||
- name: Install iptables | ||
ansible.builtin.apt: | ||
name: iptables | ||
state: present | ||
cache_valid_time: 7200 # 2h | ||
|
||
- name: Setup Wireguard server | ||
ansible.builtin.include_role: | ||
name: deadnews.util.wireguard | ||
vars: | ||
wireguard_interface: wg0 | ||
wireguard_template: templates/wg0.conf.j2 | ||
wireguard_ip_forward: true | ||
wireguard_debug: true | ||
|
||
- name: Setup Wireguard client | ||
ansible.builtin.include_role: | ||
name: deadnews.util.wireguard | ||
vars: | ||
wireguard_interface: wg1 | ||
wireguard_template: templates/wg1.conf.j2 | ||
wireguard_ip_forward: false | ||
wireguard_debug: true |
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,22 @@ | ||
--- | ||
driver: | ||
name: docker | ||
|
||
platforms: | ||
- name: ${MOLECULE_DISTRO:-debian12} | ||
image: geerlingguy/docker-${MOLECULE_DISTRO:-debian12}-ansible:latest | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
cgroupns_mode: host | ||
privileged: true | ||
pre_build_image: true | ||
|
||
provisioner: | ||
name: ansible | ||
env: | ||
ANSIBLE_VERBOSITY: 0 | ||
ANSIBLE_STDOUT_CALLBACK: community.general.yaml | ||
playbooks: | ||
converge: ${MOLECULE_PLAYBOOK:-converge.yml} | ||
prepare: ../../../../molecule/playbooks/prepare-systemd.yml |
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,12 @@ | ||
# {{ ansible_managed }} | ||
|
||
[Interface] | ||
Address = 10.0.0.1/24 | ||
ListenPort = 51820 | ||
PostDown = iptables -t nat -D POSTROUTING -o tun0 -j MASQUERADE | ||
PostUp = iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE | ||
PrivateKey = {{ wireguard_privatekey_host }} | ||
|
||
[Peer] | ||
AllowedIPs = 10.0.0.2/24 | ||
PublicKey = {{ wireguard_publickey_peer }} |
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,13 @@ | ||
# {{ ansible_managed }} | ||
|
||
[Interface] | ||
{# Unique IP for the peer #} | ||
Address = 10.0.0.2/24 | ||
{# Unique identifier for the peer, should be added to the server's configuration #} | ||
PrivateKey = {{ wireguard_privatekey_peer }} | ||
|
||
[Peer] | ||
{# Route all traffic through the VPN, except 10.0.0.0/8 #} | ||
AllowedIPs = 0.0.0.0/5, 8.0.0.0/7, 11.0.0.0/8, 12.0.0.0/6, 16.0.0.0/4, 32.0.0.0/3, 64.0.0.0/2, 128.0.0.0/1 | ||
Endpoint = {{ wireguard_host }}:51820 | ||
PublicKey = {{ wireguard_publickey_host }} |
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,42 @@ | ||
--- | ||
# Display debug information | ||
|
||
- name: Get Wireguard status — {{ wireguard_interface }} | ||
ansible.builtin.command: | ||
cmd: systemctl status wg-quick@{{ wireguard_interface }}.service | ||
changed_when: false | ||
register: wireguard_status | ||
|
||
- name: Show Wireguard status — {{ wireguard_interface }} | ||
ansible.builtin.debug: | ||
var: wireguard_status.stdout | ||
|
||
- name: Get IP address and interface details | ||
ansible.builtin.command: | ||
cmd: ip a | ||
changed_when: false | ||
register: addr_output | ||
|
||
- name: Display output of IP address and interface details | ||
ansible.builtin.debug: | ||
var: addr_output.stdout | ||
|
||
- name: Get IP routing table | ||
ansible.builtin.command: | ||
cmd: ip route | ||
changed_when: false | ||
register: route_output | ||
|
||
- name: Display output of IP routing table | ||
ansible.builtin.debug: | ||
var: route_output.stdout | ||
|
||
- name: Get Wireguard interface details | ||
ansible.builtin.command: | ||
cmd: wg show | ||
changed_when: false | ||
register: wg_output | ||
|
||
- name: Display output of Wireguard interface details | ||
ansible.builtin.debug: | ||
var: wg_output.stdout |
Oops, something went wrong.