diff --git a/roles/go/tasks/main.yml b/roles/go/tasks/main.yml new file mode 100644 index 0000000..e34f98d --- /dev/null +++ b/roles/go/tasks/main.yml @@ -0,0 +1,7 @@ +--- + +- name: Download and install go + unarchive: src=https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz dest=/usr/local copy=no + +- name: Configure go + template: src=go.sh dest=/etc/profile.d/go.sh diff --git a/roles/go/templates/go.sh b/roles/go/templates/go.sh new file mode 100644 index 0000000..ec793dd --- /dev/null +++ b/roles/go/templates/go.sh @@ -0,0 +1,2 @@ +export GOPATH=/opt/go +export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin diff --git a/roles/yanic/defaults/main.yml b/roles/yanic/defaults/main.yml new file mode 100644 index 0000000..f7084b9 --- /dev/null +++ b/roles/yanic/defaults/main.yml @@ -0,0 +1,35 @@ +--- + +yanic_publisher: false +yanic_respondd: true +yanic_respondd_collect_interval: "1m" +yanic_respondd_interface: "br-{{ site_code }}" + +yanic_webserver: false +yanic_webserver_bind: "127.0.0.1:8080" +yanic_webserver_webroot: "/var/www/html/meshviewer" + +yanic_nodes: true +yanic_nodes_state_path: "/var/lib/yanic/yanic.json" +yanic_nodes_save_interval: "5s" +yanic_nodes_offline_after: "10m" +yanic_nodes_prune_after: "7d" + +yanic_meshviewer_version: 2 +yanic_meshviewer_path: "/var/www/html/meshviewer/data" +yanic_meshviewer_nodes: "{{yanic_meshviewer_path}}/nodes.json" +yanic_meshviewer_graph: "{{yanic_meshviewer_path}}/graph.json" + +yanic_database_delete_after: "7d" +yanic_database_delete_interval: "1h" + +yanic_socket: +- enable: false + type: unix + address: "/var/lib/yanic/database.socket" +yanic_influxdb: +- enable: false + host: http://localhost:8086 + database: ffhb + username: "" + password: "" diff --git a/roles/yanic/handlers/main.yml b/roles/yanic/handlers/main.yml new file mode 100644 index 0000000..ea84862 --- /dev/null +++ b/roles/yanic/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Restart yanic + service: name=yanic state=restarted + +- name: Restart yanic-publish + service: name=yanic-publish.timer state=restarted + +- name: Reload systemd + command: systemctl daemon-reload diff --git a/roles/yanic/meta/main.yml b/roles/yanic/meta/main.yml new file mode 100644 index 0000000..53817af --- /dev/null +++ b/roles/yanic/meta/main.yml @@ -0,0 +1,4 @@ +--- + +dependencies: +- { role: go } diff --git a/roles/yanic/tasks/main.yml b/roles/yanic/tasks/main.yml new file mode 100644 index 0000000..9de42bf --- /dev/null +++ b/roles/yanic/tasks/main.yml @@ -0,0 +1,43 @@ +--- + +- name: Create users + user: name=yanic generate_ssh_key=yes ssh_key_type=rsa ssh_key_file=.ssh/id_rsa ssh_key_comment="yanic@{{inventory_hostname}}" + +- name: Install yanic + shell: /usr/local/go/bin/go get -u github.com/FreifunkBremen/yanic/cmd/yanic + environment: + GOPATH: /opt/go + notify: Restart yanic + +- name: Configure yanic + template: src=config.toml dest=/etc/yanic.conf + notify: Restart yanic + +- name: Create directories + file: path={{ item }}/ state=directory owner=yanic + with_items: + - "{{ yanic_meshviewer_path }}" + - /var/lib/yanic + +- name: Install system unit + template: src=yanic.service dest=/lib/systemd/system/yanic.service + notify: + - Reload systemd + - Restart yanic + +- name: Enable yanic + service: name=yanic enabled=yes + +- name: Install system publish unit + template: src={{item}} dest=/lib/systemd/system/{{item}} + when: yanic_publisher + with_items: + - yanic-publish.service + - yanic-publish.timer + notify: + - Reload systemd + - Restart yanic-publish + +- name: Enable yanic-publish + service: name=yanic-publish.timer enabled=yes + when: yanic_publisher diff --git a/roles/yanic/templates/config.toml b/roles/yanic/templates/config.toml new file mode 100644 index 0000000..733a0dc --- /dev/null +++ b/roles/yanic/templates/config.toml @@ -0,0 +1,43 @@ +# {{ ansible_managed }} +[respondd] +enable = {{ yanic_respondd | ternary('true','false') }} +collect_interval = "{{ yanic_respondd_collect_interval }}" +interface = "{{ yanic_respondd_interface }}" + +[webserver] +enable = {{ yanic_webserver | ternary('true','false') }} +bind = "{{ yanic_webserver_bind }}" +webroot = "{{ yanic_webserver_webroot }}" + +[nodes] +enable = {{yanic_nodes | ternary('true','false') }} +state_path = "{{yanic_nodes_state_path}}" +save_interval = "{{yanic_nodes_save_interval}}" +offline_after = "{{yanic_nodes_offline_after}}" +prune_after = "{{yanic_nodes_prune_after}}" + + +[meshviewer] +version = {{yanic_meshviewer_version}} +nodes_path = "{{yanic_meshviewer_nodes}}" +graph_path = "{{yanic_meshviewer_graph}}" + +[database] +delete_after = "{{ yanic_database_delete_after }}" +delete_interval = "{{ yanic_database_delete_interval }}" + +{% for db in yanic_influxdb %} +[[database.connection.influxdb]] +enable = {{ db.enable | ternary('true','false') }} +address = "{{ db.host }}" +database = "{{ db.database }}" +username = "{{ db.username }}" +password = "{{ db.password }}" +{% endfor %} + +{% for db in yanic_socket %} +[[database.connection.socket]] +enable = {{ db.enable | ternary('true','false') }} +type = "{{ db.type }}" +address = "{{ db.address }}" +{% endfor %} diff --git a/roles/yanic/templates/yanic-publish.service b/roles/yanic/templates/yanic-publish.service new file mode 100644 index 0000000..fc186df --- /dev/null +++ b/roles/yanic/templates/yanic-publish.service @@ -0,0 +1,10 @@ +[Unit] +Description=Publish data of yanic on downloads server + +[Service] +ExecStart=/usr/bin/rsync --del -rt {{ yanic_nodes_path }}/ downloads@webserver.bremen.freifunk.net:data/yanic +User=yanic +Type=oneshot + +[Install] +WantedBy=multi-user.target diff --git a/roles/yanic/templates/yanic-publish.timer b/roles/yanic/templates/yanic-publish.timer new file mode 100644 index 0000000..6d1267a --- /dev/null +++ b/roles/yanic/templates/yanic-publish.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Publish data of yanic on downloads server every minute + +[Timer] +OnBootSec=15min +OnUnitActiveSec=1min + +[Install] +WantedBy=timers.target diff --git a/roles/yanic/templates/yanic.service b/roles/yanic/templates/yanic.service new file mode 100644 index 0000000..82e44a5 --- /dev/null +++ b/roles/yanic/templates/yanic.service @@ -0,0 +1,13 @@ +[Unit] +Description=yanic + +[Service] +Type=simple +User=yanic +ExecStart=/opt/go/bin/yanic -config /etc/yanic.conf +Restart=always +RestartSec=5s +Environment=PATH=/usr/bin:/usr/local/bin + +[Install] +WantedBy=multi-user.target diff --git a/site.yml b/site.yml index 77cc31f..ab4c353 100644 --- a/site.yml +++ b/site.yml @@ -17,6 +17,7 @@ - dns - dhcpd - respondd + - yanic - name: Setup confluence server hosts: confluence.regensburg.freifunk.net