innernet-playbook/roles/server/tasks/main.yml
2021-11-15 19:08:54 +01:00

86 lines
2.4 KiB
YAML

# SPDX-FileCopyrightText: 2021 Free Software Foundation Europe <https://fsfe.org>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
---
- name: Install needed packages
apt:
package:
- rsync
- wireguard
- wireguard-tools
- name: Copy binary to server
synchronize:
src: "innernet-server"
dest: "/usr/bin/"
- name: Create alias ("inns")
lineinfile:
path: "/root/.bashrc"
line: '"alias inns="innernet-server"'
- name: Create base network
shell: |
innernet-server new \
--network-name "{{ network_name }}" \
--network-cidr "{{ network_cidr }}" \
--external-endpoint "[{{ hostvars[inventory_hostname]['ansible_default_ipv6']['address'] }}]:{{ network_listen_port }}" \
--listen-port {{ network_listen_port }}
# FIXME innernet gives an error if network exists already
ignore_errors: true
- name: Create CIDRs
shell: |
innernet-server add-cidr "{{ network_name }}" \
--parent "{{ item.parent }}" \
--name "{{ item.name }}" \
--cidr "{{ item.cidr }}" \
--yes
with_items: "{{ cidrs }}"
# FIXME innernet gives an error if CIDR exists already
ignore_errors: true
- name: Create admin peers
shell: |
innernet-server add-peer "{{ network_name }}" \
--name "{{ item.name }}" \
--cidr "{{ item.cidr }}" \
--admin true \
--save-config "{{ item.name }}.toml" \
--invite-expires "14d" \
--auto-ip \
--yes
with_items: "{{ admin_peers }}"
# FIXME innernet gives an error if admin peer exists already
ignore_errors: true
- name: Create peers
shell: |
innernet-server add-peer "{{ network_name }}" \
--name "{{ item.name }}" \
--cidr "{{ item.cidr }}" \
--admin false \
--save-config "{{ item.name }}.toml" \
--invite-expires "14d" \
--auto-ip \
--yes
with_items: "{{ peers }}"
# FIXME innernet gives an error if peer exists already
ignore_errors: true
- name: Copy invitation files of admin peers to controller
# other machines should never be admins. Only humans.
synchronize:
src: "/root/{{ item.name }}.toml"
dest: "{{ playbook_dir }}/roles/client/files/{{ item.name }}_admin.toml"
mode: pull
with_items: "{{ admin_peers }}"
- name: Copy invitation files of peers to controller
synchronize:
src: "/root/{{ item.name }}.toml"
dest: "{{ playbook_dir }}/roles/client/files/{{ item.name }}.toml"
mode: pull
with_items: "{{ peers }}"