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..03cf4cf --- /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: wg0 + #ipv6_format: fc12::%02x%02x:%02x%02x/%d + #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..595e19e --- /dev/null +++ b/wireguard-ipv6-converter/tasks/deploy.yml @@ -0,0 +1,11 @@ +- name: Get architecture + set_fact: + arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'arm64' }}" + versionUri: "{% if wireguard_ipv6_converter.version == 'latest' %}latest/download{% else %}download/{{ wireguard_ipv6_converter.version }}{% endif %}" + +- name: Download binary + get_url: + url: https://github.com/Ruakij/wg-ipv6-converter/releases/{{ versionUri }}/wg-ipv6-converter_{{ arch }} + dest: /usr/local/bin/wg-ipv6-converter + mode: "744" + register: deployDownload 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..c12fc5c --- /dev/null +++ b/wireguard-ipv6-converter/tasks/setup-service.yml @@ -0,0 +1,17 @@ +- 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: serviceFile + +- name: Enable service + ansible.builtin.service: + name: wg-ipv6-converter_{{ wireguard_ipv6_converter.setup.interface }} + daemon-reload: true + enabled: true + +- name: Start service if interface exists already + ansible.builtin.service: + name: wg-ipv6-converter_{{ wireguard_ipv6_converter.setup.interface }} + state: "{{ 'restarted' if deployDownload.changed or serviceFile.changed else 'started' }}" + when: "wireguard_ipv6_converter.setup.interface in ansible_interfaces" 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..e1544a0 --- /dev/null +++ b/wireguard-ipv6-converter/templates/wg-ipv6-conv.service.jinja2 @@ -0,0 +1,29 @@ +[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 }}" +{% if wireguard_ipv6_converter.setup.ipv6_format is defined %} +Environment="IPV6_FORMAT={{ wireguard_ipv6_converter.setup.ipv6_format }}" +{% endif %} +{% if wireguard_ipv6_converter.setup.filter_prefix is defined %} +Environment="FILTER_PREFIX={{ wireguard_ipv6_converter.setup.filter_prefix }}" +{% endif %} +{% if wireguard_ipv6_converter.setup.recheck_interval is defined %} +Environment="RECHECK_INTERVAL={{ wireguard_ipv6_converter.setup.recheck_interval }}" +{% endif %} + +[Install] +WantedBy=multi-user.target