diff --git a/bird-config.j2 b/bird-config.j2 new file mode 100644 index 0000000..b95bf3c --- /dev/null +++ b/bird-config.j2 @@ -0,0 +1,24 @@ +protocol device { + scan time 10; +}; + +protocol direct { + ipv4; + ipv6; + interface "dn42dummy0"; +}; + +protocol babel int_babel { + randomize router id on; + ipv4 { + import all; + export all; + }; + ipv6 { + import all; + export all; + }; + interface "{% if vlan is defined %}host0.{{ vlan }}{% else %}host0{% endif %}" { + type wired; + }; +}; diff --git a/deploy.yml b/deploy.yml new file mode 100644 index 0000000..56b84ab --- /dev/null +++ b/deploy.yml @@ -0,0 +1,68 @@ +- hosts: all + remote_user: root + tasks: + - name: install debian dependencies + package: + name: nginx,bird2 + state: present + when: ansible_distribution == 'Debian' + - name: install arch dependencies + pacman: + name: nginx,bird + state: present + when: ansible_distribution == 'Archlinux' + - name: see if host0 exists / if this is a systemd-nspawn container + stat: + path: /sys/class/net/host0 + register: host0 + - name: configure host0 + template: + src: host0-network.j2 + dest: /etc/systemd/network/10-host0.network + - name: configure host0 vlan .netdev + template: + src: host0-vlan-netdev.j2 + dest: /etc/systemd/network/host0-vlan.netdev + when: vlan is defined + - name: configure host0 vlan .network + template: + src: host0-vlan-network.j2 + dest: /etc/systemd/network/host0-vlan.network + when: vlan is defined + - name: configure dummy interface .netdev + template: + src: dn42dummy0-netdev.j2 + dest: /etc/systemd/network/dn42dummy0.netdev + - name: configure dummy interface .network + template: + src: dn42dummy0-network.j2 + dest: /etc/systemd/network/dn42dummy0.network + - name: add nginx config + template: + src: nginx-global.j2 + dest: /etc/nginx/nginx.conf + - name: add bird config on arch + template: + src: bird-config.j2 + dest: /etc/bird.conf + when: ansible_distribution == 'Archlinux' + - name: add bird config on debian + template: + src: bird-config.j2 + dest: /etc/bird/bird.conf + when: ansible_distribution == 'Debian' + - name: enable and reload/start systemd-networkd + systemd: + state: reloaded + name: systemd-networkd.service + enabled: true + - name: enable and reload/start nginx + systemd: + state: reloaded + name: nginx.service + enabled: true + - name: enable and reload/start bird + systemd: + state: reloaded + name: bird.service + enabled: true diff --git a/dn42dummy0-netdev.j2 b/dn42dummy0-netdev.j2 new file mode 100644 index 0000000..f4c5b62 --- /dev/null +++ b/dn42dummy0-netdev.j2 @@ -0,0 +1,3 @@ +[NetDev] +Name=dn42dummy0 +Kind=dummy diff --git a/dn42dummy0-network.j2 b/dn42dummy0-network.j2 new file mode 100644 index 0000000..f14de6a --- /dev/null +++ b/dn42dummy0-network.j2 @@ -0,0 +1,8 @@ +[Match] +Name=dn42dummy0 + +[Network] +Address=fd32:6b0:70a6:8181::81/128 +{% if unicastv6 is defined %} +Address={{ unicastv6 }}/128 +{% endif %} diff --git a/dn42routes.j2 b/dn42routes.j2 new file mode 100644 index 0000000..b42688b --- /dev/null +++ b/dn42routes.j2 @@ -0,0 +1,22 @@ +[Route] +Destination=10.0.0.0/8 +Gateway=_dhcp4 +Metric=1024 + +[Route] +Destination=172.20.0.0/14 +Gateway=_dhcp4 +Metric=1024 + +[Route] +Destination=172.31.0.0/16 +Gateway=_dhcp4 +Metric=1024 + +[Route] +Destination=fd00::/8 +Gateway=_ipv6ra +Metric=1024 +{% if unicastv6 is defined %} +PreferredSource={{ unicastv6 }} +{% endif %} diff --git a/host0-network.j2 b/host0-network.j2 new file mode 100644 index 0000000..ce8164a --- /dev/null +++ b/host0-network.j2 @@ -0,0 +1,21 @@ +[Match] +Name=host0 + +[Network] +DHCP=true +IPv6AcceptRA=true +LinkLocalAddressing=ipv6 +{% if vlan is defined %} +VLAN=br0.{{ vlan }} +{% endif %} + +# These route metrics have to be higher than everything else +[DHCPv4] +RouteMetric=2048 + +[IPv6AcceptRA] +RouteMetric=2048 + +{% if vlan is undefined %} +{% include 'dn42routes.j2' %} +{% endif %} diff --git a/host0-vlan-netdev.j2 b/host0-vlan-netdev.j2 new file mode 100644 index 0000000..752e178 --- /dev/null +++ b/host0-vlan-netdev.j2 @@ -0,0 +1,6 @@ +[NetDev] +Name=host0.{{ vlan }} +Kind=vlan + +[VLAN] +Id={{ vlan }} diff --git a/host0-vlan-network.j2 b/host0-vlan-network.j2 new file mode 100644 index 0000000..dd7f7ce --- /dev/null +++ b/host0-vlan-network.j2 @@ -0,0 +1,17 @@ +[Match] +Name=host0.{{ vlan }} + +[Network] +DHCP=true +IPv6AcceptRA=true + +[DHCPv4] +RouteMetric=1024 +UseRoutes=false +UseGateway=false + +[IPv6AcceptRA] +UseGateway=false +UseRoutePrefix=false + +{% include 'dn42routes.j2' %} diff --git a/inventory.yml b/inventory.yml new file mode 100644 index 0000000..52b1f02 --- /dev/null +++ b/inventory.yml @@ -0,0 +1,6 @@ +all: + hosts: + us1.myip.9pfs.dn42: + ansible_host: fd32:6b0:70a6:8181::1 + unicastv6: fd32:6b0:70a6:8181::1 + fqdn: us1.myip.9pfs.dn42 diff --git a/nginx-global.j2 b/nginx-global.j2 new file mode 100644 index 0000000..177e1c3 --- /dev/null +++ b/nginx-global.j2 @@ -0,0 +1,11 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + sendfile on; + keepalive_timeout 65; +{% include 'nginx-site.j2' %} +} diff --git a/nginx-site.j2 b/nginx-site.j2 index 1a0e19d..e0949f1 100644 --- a/nginx-site.j2 +++ b/nginx-site.j2 @@ -1,24 +1,24 @@ server { listen [fd32:6b0:70a6:8181::81]:80; - {% if unicastv6 is defined %} +{% if unicastv6 is defined %} listen [{{ unicastv6 }}]:80; - {% endif %} +{% endif %} server_name myip.9pfs.dn42; server_name *.myip.9pfs.dn42; server_name [fd32:6b0:70a6:8181::81]; - {% if unicastv6 is defined %} - listen [{{ unicastv6 }}]; - {% endif %} +{% if unicastv6 is defined %} + server_name [{{ unicastv6 }}]; +{% endif %} location = /raw { return 200 '$remote_addr\n'; default_type text/plain; } - + location = /api { default_type application/json; add_header 'Access-Control-Allow-Origin' '*'; - return 200 '{\n\t"version": "1.0",\n\t"ip": "$remote_addr",\n\t"server": "$server_addr",\n\t"node_as": "4242422002",\n\t"node_location": "{% if country is defined %}{{ country }}{% else %}US{% endif %},\n\t"node_id": "{% if fqdn is defined %}{{ fqdn }}{% else %}myip.9pfs.dn42{% endif %}"\n}'; + return 200 '{\n\t"version": "1.0",\n\t"ip": "$remote_addr",\n\t"server": "$server_addr",\n\t"node_as": "4242422002",\n\t"node_location": "{% if country is defined %}{{ country }}{% else %}US{% endif %}",\n\t"node_id": "{% if fqdn is defined %}{{ fqdn }}{% else %}myip.9pfs.dn42{% endif %}"\n}'; } location = / { {% include 'nginx-html.j2' %}