From 248a3c08b854bc1c56f5f713fd50fc810519ff4a Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 12 Apr 2023 13:36:14 +0200 Subject: [PATCH] Initial role-data --- .../defaults/wireguard-ipv6-converter.yml | 12 ++++++++++ wireguard-ipv6-converter/tasks/deploy.yml | 9 ++++++++ wireguard-ipv6-converter/tasks/main.yml | 3 +++ .../tasks/setup-service.yml | 12 ++++++++++ .../templates/wg-ipv6-conv.service.jinja2 | 23 +++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 wireguard-ipv6-converter/defaults/wireguard-ipv6-converter.yml create mode 100644 wireguard-ipv6-converter/tasks/deploy.yml create mode 100644 wireguard-ipv6-converter/tasks/main.yml create mode 100644 wireguard-ipv6-converter/tasks/setup-service.yml create mode 100644 wireguard-ipv6-converter/templates/wg-ipv6-conv.service.jinja2 diff --git a/wireguard-ipv6-converter/defaults/wireguard-ipv6-converter.yml b/wireguard-ipv6-converter/defaults/wireguard-ipv6-converter.yml new file mode 100644 index 0000000..5f7ec36 --- /dev/null +++ b/wireguard-ipv6-converter/defaults/wireguard-ipv6-converter.yml @@ -0,0 +1,12 @@ +wireguard_ipv6_converter: + version: latest + + # see https://github.com/Ruakij/wg-ipv6-converter#31-environment + setup: + interface: wt0 + ipv6_format: "" + filter_prefix: 100.100 + recheck_interval: 60s + + service: + bindTo: netbird.service diff --git a/wireguard-ipv6-converter/tasks/deploy.yml b/wireguard-ipv6-converter/tasks/deploy.yml new file mode 100644 index 0000000..ce13231 --- /dev/null +++ b/wireguard-ipv6-converter/tasks/deploy.yml @@ -0,0 +1,9 @@ +- name: Get architecture + set_fact: + arch: {{ 'amd64' if ansible_architecture == 'x86_64' elif 'amd64' if ansible_architecture == 'aarch64' }} + +- name: Download binary + get_url: + url: https://github.com/Ruakij/wg-ipv6-converter/releases/download/{{ wireguard_ipv6_converter.version }}/wg-ipv6-converter_{{ arch }} + dest: /usr/bin/local/wg-ipv6-converter + mode: "744" diff --git a/wireguard-ipv6-converter/tasks/main.yml b/wireguard-ipv6-converter/tasks/main.yml new file mode 100644 index 0000000..bc96e37 --- /dev/null +++ b/wireguard-ipv6-converter/tasks/main.yml @@ -0,0 +1,3 @@ +- import_tasks: ./deploy.yml + +- import_tasks: ./setup-service.yml diff --git a/wireguard-ipv6-converter/tasks/setup-service.yml b/wireguard-ipv6-converter/tasks/setup-service.yml new file mode 100644 index 0000000..b733887 --- /dev/null +++ b/wireguard-ipv6-converter/tasks/setup-service.yml @@ -0,0 +1,12 @@ +- name: Deploy service + ansible.builtin.template: + src: wg-ipv6-conv.service.jinja2 + dest: /etc/systemd/system/wg-ipv6-converter_{{ wireguard_ipv6_converter.setup.interface }}.service + register: service-file + +- name: Enable service + ansible.builtin.service: + name: wg-ipv6-converter_{{ wireguard_ipv6_converter.setup.interface }} + state: '{{ 'restarted' if service-file.changed else 'started' }}' + enabled: true + diff --git a/wireguard-ipv6-converter/templates/wg-ipv6-conv.service.jinja2 b/wireguard-ipv6-converter/templates/wg-ipv6-conv.service.jinja2 new file mode 100644 index 0000000..7d85dcc --- /dev/null +++ b/wireguard-ipv6-converter/templates/wg-ipv6-conv.service.jinja2 @@ -0,0 +1,23 @@ +[Unit] +Description=WireGuard IPv6 converter for {{ wireguard_ipv6_converter.setup.interface }} +{% if wireguard_ipv6_converter.service.bindTo is defined %} +BindsTo={{ wireguard_ipv6_converter.service.bindTo }} +After={{ wireguard_ipv6_converter.service.bindTo }} +{% endif %} + +[Service] +Type=simple +{% if wireguard_ipv6_converter.service.bindTo is defined %} +ExecStartPre=/bin/sleep 10 +{% endif %} +ExecStart=/usr/local/bin/wg-ipv6-converter +Restart=always +RestartSec=30 + +Environment="INTERFACE={{ wireguard_ipv6_converter.setup.interface }}" +Environment="IPV6_FORMAT={{ wireguard_ipv6_converter.setup.ipv6_format }}" +Environment="FILTER_PREFIX={{ wireguard_ipv6_converter.setup.filter_prefix }}" +Environment="RECHECK_INTERVAL={{ wireguard_ipv6_converter.setup.recheck_interval }}" + +[Install] +WantedBy=multi-user.target