2021-11-15 19:09:18 +01:00
|
|
|
# SPDX-FileCopyrightText: 2021 Free Software Foundation Europe <https://fsfe.org>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
---
|
2022-03-02 17:12:10 +01:00
|
|
|
- name: Convert hostname to innernet peer name
|
|
|
|
tags: [peers]
|
|
|
|
# we want the mere host name before the domain, so e.g.
|
|
|
|
# * server1.fsfe.org -> server1
|
|
|
|
# * cont1.noris.fsfeurope.org -> cont1-noris
|
|
|
|
set_fact:
|
|
|
|
innernet_client: "{{ innernet_client | replace(item.0, item.1) }}"
|
|
|
|
vars:
|
|
|
|
- innernet_client: "{{ ansible_host }}"
|
|
|
|
loop:
|
|
|
|
- ['.', '-']
|
|
|
|
- ['-fsfeurope-org', '']
|
|
|
|
- ['-fsfe-org', '']
|
|
|
|
- ['-fsfe-be', '']
|
|
|
|
|
|
|
|
- name: Gather which packages are installed on the client
|
|
|
|
tags: [update]
|
|
|
|
package_facts:
|
|
|
|
manager: auto
|
|
|
|
|
|
|
|
- name: Make sure needed packages for innernet and wireguard are installed
|
2021-12-20 17:56:30 +01:00
|
|
|
apt:
|
|
|
|
package:
|
|
|
|
- python3-pexpect
|
2022-03-02 17:12:10 +01:00
|
|
|
- rsync
|
|
|
|
- wireguard
|
|
|
|
- wireguard-tools
|
|
|
|
- ufw
|
2021-12-20 17:56:30 +01:00
|
|
|
|
|
|
|
- name: Remove existing innernet
|
|
|
|
tags: [never, uninstall]
|
|
|
|
expect:
|
|
|
|
command: "innernet uninstall {{ network_name }}"
|
|
|
|
responses:
|
|
|
|
(?i)delete: "yes"
|
|
|
|
|
2022-03-02 17:12:10 +01:00
|
|
|
- name: Install innernet package on client
|
2022-01-21 17:18:29 +01:00
|
|
|
tags: [update]
|
2022-03-02 17:12:10 +01:00
|
|
|
block:
|
|
|
|
- name: Copy innernet package to client
|
|
|
|
synchronize:
|
|
|
|
src: "innernet.deb"
|
|
|
|
dest: "/tmp/innernet.deb"
|
2021-11-15 19:09:18 +01:00
|
|
|
|
2022-03-02 17:12:10 +01:00
|
|
|
- name: Install innernet client package
|
|
|
|
apt:
|
|
|
|
deb: "/tmp/innernet.deb"
|
|
|
|
update_cache: true
|
|
|
|
install_recommends: true
|
|
|
|
# If 1. innernet not installed or 2. `update` tag executed
|
|
|
|
when: "'innernet' not in ansible_facts.packages or 'update' in ansible_run_tags"
|
|
|
|
|
2022-03-03 10:58:48 +01:00
|
|
|
- name: Get existing peers from innernet-server database
|
2022-03-03 11:12:06 +01:00
|
|
|
tags: [peers]
|
2022-03-03 10:58:48 +01:00
|
|
|
shell: 'sqlite3 /var/lib/innernet-server/{{ network_name }}.db "select name from peers;"'
|
|
|
|
register: existing_peers
|
|
|
|
delegate_to: "{{ innernet_server }}"
|
|
|
|
run_once: true
|
2022-03-02 17:12:10 +01:00
|
|
|
|
2022-03-03 10:58:48 +01:00
|
|
|
- name: Add machine as innernet peer
|
|
|
|
tags: [peers]
|
2022-03-03 11:04:31 +01:00
|
|
|
include_role:
|
|
|
|
name: server
|
|
|
|
tasks_from: add_peer
|
2022-03-03 10:58:48 +01:00
|
|
|
args:
|
|
|
|
apply:
|
|
|
|
tags: [peers]
|
2022-03-02 17:12:10 +01:00
|
|
|
delegate_to: "{{ innernet_server }}"
|
2022-03-03 10:58:48 +01:00
|
|
|
vars:
|
|
|
|
peer_name: "{{ innernet_client }}"
|
|
|
|
# Value of the CIDR we defined as the CIDR for machines
|
2022-03-03 11:12:06 +01:00
|
|
|
peer_cidr: "{{ machine_cidr }}"
|
2022-03-03 10:58:48 +01:00
|
|
|
# machines are never admins
|
|
|
|
peer_admin: "false"
|
|
|
|
when:
|
|
|
|
- innernet_client not in existing_peers.stdout_lines
|
2022-03-02 17:12:10 +01:00
|
|
|
|
2022-03-03 10:58:48 +01:00
|
|
|
- name: Install innernet peer invitation on machine
|
|
|
|
tags: [peers]
|
|
|
|
block:
|
2022-03-02 17:12:10 +01:00
|
|
|
- name: Copy peer invitation file from controller to client
|
|
|
|
copy:
|
|
|
|
src: "{{ innernet_client }}.toml"
|
|
|
|
dest: "/root/{{ innernet_client }}.toml"
|
|
|
|
|
|
|
|
- name: Install peer invitation on client
|
|
|
|
shell: |
|
|
|
|
innernet install /root/{{ innernet_client }}.toml \
|
|
|
|
--default-name \
|
|
|
|
--delete-invite
|
2021-11-15 19:09:18 +01:00
|
|
|
when:
|
2022-03-02 17:12:10 +01:00
|
|
|
- innernet_client not in existing_peers.stdout_lines
|
2021-12-02 17:46:40 +01:00
|
|
|
|
2022-01-20 17:52:37 +01:00
|
|
|
- name: Set listen port
|
|
|
|
tags: [listen_port]
|
2022-03-02 17:12:10 +01:00
|
|
|
ini_file:
|
2022-01-20 17:52:37 +01:00
|
|
|
path: "/etc/innernet/{{ network_name }}.conf"
|
|
|
|
section: interface
|
|
|
|
option: listen-port
|
|
|
|
value: "{{ network_listen_port }}"
|
|
|
|
mode: 600
|
|
|
|
backup: yes
|
|
|
|
|
|
|
|
- name: Allow UDP traffic on WireGuard port
|
|
|
|
tags: [listen_port, firewall]
|
|
|
|
ufw:
|
|
|
|
to_port: "{{ network_listen_port }}"
|
|
|
|
rule: allow
|
|
|
|
proto: udp
|
|
|
|
|
|
|
|
- name: Restart and enable innernet daemon
|
2022-03-02 17:12:10 +01:00
|
|
|
systemd:
|
2021-12-02 17:46:40 +01:00
|
|
|
name: "innernet@{{ network_name }}"
|
2022-01-20 17:52:37 +01:00
|
|
|
state: restarted
|
2022-03-02 17:12:10 +01:00
|
|
|
enabled: yes
|
|
|
|
daemon_reload: yes
|