From 88689bf77be52080ba1f06d68f2494d5f054d8e5 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Sun, 19 Aug 2018 19:59:32 -0700
Subject: [PATCH] Basic, working role

---
 defaults/main.yml      | 16 +++++++++++++++-
 tasks/main.yml         | 32 +++++++++++++++++++++++++++++++-
 templates/config.j2    | 18 ++++++++++++++++++
 templates/logrotate.j2 |  7 +++++++
 4 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 templates/logrotate.j2

diff --git a/defaults/main.yml b/defaults/main.yml
index 4f43c51..aac7d0e 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,2 +1,16 @@
 ---
-# defaults file for eth-log-alerting
\ No newline at end of file
+eth_log_alerting_binary_url: "https://git.ethitter.com/debian/eth-log-alerting/uploads/73fb61dcec9e953d24f1180d03959e4c/eth-log-alerting_linux_amd64"
+eth_log_alerting_binary_dest: /usr/local/bin/eth-log-alerting
+eth_log_alerting_config_dest: /etc/eth-log-alerting.json
+
+eth_log_alerting_debug_dest: "os.Stdout"
+eth_log_alerting_debug: false
+
+eth_log_alerting_logs:
+ - log_path: ""
+   webhook_url: ""
+   username: ""
+   channel: ""
+   color: ""
+   icon_url: ""
+   search: ""
diff --git a/tasks/main.yml b/tasks/main.yml
index ccad619..a3008f6 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,2 +1,32 @@
 ---
-# tasks file for eth-log-alerting
\ No newline at end of file
+- name: Download and install binary
+  get_url:
+    url: "{{ eth_log_alerting_binary_url }}"
+    dest: "{{ eth_log_alerting_binary_dest }}"
+    mode: 0755
+    force: yes
+
+- name: Set configuration
+  template:
+    src: templates/config.j2
+    dest: "{{ eth_log_alerting_config_dest }}"
+    force: yes
+    owner: root
+    group: root
+    mode: 0400
+
+- name: Configure logrotate
+  template:
+    src: templates/logrotate.j2
+    dest: /etc/logrotate.d/eth-log-alerting
+    force: yes
+    owner: root
+    group: root
+    mode: 0644
+  when: eth_log_alerting_debug_dest != "os.Stdout"
+
+- name: Remove logrotate configuration
+  file:
+    dest: /etc/logrotate.d/eth-log-alerting
+    state: absent
+  when: eth_log_alerting_debug_dest == "os.Stdout"
diff --git a/templates/config.j2 b/templates/config.j2
index e69de29..0060bae 100644
--- a/templates/config.j2
+++ b/templates/config.j2
@@ -0,0 +1,18 @@
+{
+    "debug-dest": "{{ eth_log_alerting_debug_dest }}",
+    "debug": {{ eth_log_alerting_debug|lower }},
+    "logs": [
+        {% for item in eth_log_alerting_logs %}{% if 0 != loop.index0 %},{% endif %}
+
+        {
+            "log_path": "{{ item.log_path }}",
+            "webhook_url": "{{ item.webhook_url }}",
+            "username": "{{ item.username }}",
+            "channel": "{{ item.channel }}",
+            "color": "{{ item.color }}",
+            "icon_url": "{{ item.icon_url }}",
+            "search": "{{ item.search }}"
+        }
+        {% endfor %}
+    ]
+}
diff --git a/templates/logrotate.j2 b/templates/logrotate.j2
new file mode 100644
index 0000000..5ea27ab
--- /dev/null
+++ b/templates/logrotate.j2
@@ -0,0 +1,7 @@
+{{ eth_log_alerting_debug_dest }} {
+  daily
+  rotate 14
+  notifempty
+  missingok
+  compress
+}
-- 
GitLab