diff --git a/inventory/group_vars/ffmwu-monitoring b/inventory/group_vars/ffmwu-monitoring index 85bafb5..da70e13 100644 --- a/inventory/group_vars/ffmwu-monitoring +++ b/inventory/group_vars/ffmwu-monitoring @@ -14,3 +14,8 @@ prometheus_components: - prometheus - alertmanager - node_exporter + +gopath: "/opt/go" + +yanic_blacklist: + - 98ded0c5e0c0 diff --git a/roles/service-yanic/defaults/main.yml b/roles/service-yanic/defaults/main.yml new file mode 100644 index 0000000..8660cb5 --- /dev/null +++ b/roles/service-yanic/defaults/main.yml @@ -0,0 +1,6 @@ +--- +yanic_user: "yanic" +yanic_home: "/var/lib/yanic" +yanic_path: "{{ gopath }}/bin/yanic" +yanic_config: "/etc/yanic.conf" +yanic_database: "yanic" diff --git a/roles/service-yanic/handlers/main.yml b/roles/service-yanic/handlers/main.yml new file mode 100644 index 0000000..49bf8c8 --- /dev/null +++ b/roles/service-yanic/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: reload systemd + systemd: + daemon_reload: yes + +- name: restart yanic + systemd: + name: yanic + state: restarted diff --git a/roles/service-yanic/meta/main.yml b/roles/service-yanic/meta/main.yml new file mode 100644 index 0000000..fdc1d82 --- /dev/null +++ b/roles/service-yanic/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - { role: golang } + - { role: service-influxdb } diff --git a/roles/service-yanic/tasks/main.yml b/roles/service-yanic/tasks/main.yml new file mode 100644 index 0000000..ec21e64 --- /dev/null +++ b/roles/service-yanic/tasks/main.yml @@ -0,0 +1,40 @@ +--- +- name: create Yanic system user + user: + name: "{{ yanic_user }}" + home: "{{ yanic_home }}" + shell: /bin/false + +- name: create data dir + file: + path: "{{ yanic_home }}/data" + state: directory + owner: yanic + group: yanic + mode: 0755 + +- name: create database + influxdb_database: + database_name: "{{ yanic_database }}" + +- name: write Yanic config + template: + src: "yanic.conf.j2" + dest: "{{ yanic_config }}" + notify: restart yanic + +- name: create systemd unit for Yanic + template: + src: "yanic.service.j2" + dest: "/etc/systemd/system/yanic.service" + notify: reload systemd + +- name: build Yanic binary + shell: "GOPATH={{ gopath }} go get -v -u github.com/FreifunkBremen/yanic" + notify: restart yanic + +- name: configure Yanic systemd unit + systemd: + name: "yanic.service" + enabled: yes + state: started diff --git a/roles/service-yanic/templates/yanic.conf.j2 b/roles/service-yanic/templates/yanic.conf.j2 new file mode 100644 index 0000000..03642e9 --- /dev/null +++ b/roles/service-yanic/templates/yanic.conf.j2 @@ -0,0 +1,60 @@ +# +# {{ ansible_managed }} +# + +[respondd] +enable = true +synchronize = "1m" +collect_interval = "1m" + +{% for mesh in meshes %} +[respondd.sites.{{ mesh.site_code }}] +{% if mesh.sites_virtual is defined %} +{% for site, name in mesh.sites_virtual.items() %} +[respondd.sites.{{ site }}] +{% endfor %} +{% endif %} +{% endfor %} + +{% for mesh in meshes %} +[[respondd.interfaces]] +ifname = "{{mesh.id}}br" +{% endfor %} + +[nodes] +state_path = "/var/lib/yanic/state.json" +prune_after = "30d" +save_interval = "5s" +offline_after = "10m" + +[[nodes.output.meshviewer-ffrgb]] +enable = true +path = "/var/lib/yanic/data/meshviewer.json" +[nodes.output.meshviewer-ffrgb.filter] +no_owner = true +{% if yanic_blacklist is defined %} +blacklist = [{% for node in yanic_blacklist %}"{{ node }}"{% if not loop.last %},{% endif %}{% endfor %}] +{% endif %} + +[[nodes.output.meshviewer]] +enable = true +version = 2 +nodes_path = "/var/lib/yanic/data/nodes.json" +graph_path = "/var/lib/yanic/data/graph.json" +[nodes.output.meshviewer.filter] +no_owner = true + +[[nodes.output.nodelist]] +enable = true +path = "/var/lib/yanic/data/nodelist.json" + +[database] +delete_after = "30d" +delete_interval = "1h" + +[[database.connection.influxdb]] +enable = true +address = "http://localhost:8086" +database = "yanic" +username = "" +password = "" diff --git a/roles/service-yanic/templates/yanic.service.j2 b/roles/service-yanic/templates/yanic.service.j2 new file mode 100644 index 0000000..7417d76 --- /dev/null +++ b/roles/service-yanic/templates/yanic.service.j2 @@ -0,0 +1,18 @@ +[Unit] +Description=Yanic - Yet another node info collector +Documentation=https://github.com/FreifunkBremen/yanic +Wants=network-online.target +After=network-online.target + +[Service] +Type=simple + +User={{ yanic_user }} +Group={{ yanic_user }} + +ExecStart={{ yanic_path }} serve --config {{ yanic_config }} +Restart=always +RestartSec=5s + +[Install] +WantedBy=multi-user.target