Added bitcoind-prometheus-exporter role.
authorLuke Hoersten <luke@hoersten.org>
Sat, 16 May 2020 17:59:15 -0500
changeset 9 ddf84e986362
parent 8 fd72f6774874
child 10 26ed67281db6
Added bitcoind-prometheus-exporter role.
bitcoind-prometheus-exporter/defaults/main.yaml
bitcoind-prometheus-exporter/handlers/main.yaml
bitcoind-prometheus-exporter/tasks/main.yaml
bitcoind-prometheus-exporter/templates/bitcoind-prometheus-exporter.service.j2
bitcoind/tasks/main.yaml
lnd/tasks/main.yaml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind-prometheus-exporter/defaults/main.yaml	Sat May 16 17:59:15 2020 -0500
@@ -0,0 +1,6 @@
+---
+
+bitcoind_prometheus_exporter_conf: "/home/bitcoin/.bitcoin/bitcoin.conf"
+bitcoind_prometheus_exporter_version: "0.5.0"
+bitcoind_prometheus_exporter_url: "https://github.com/jvstein/bitcoin-prometheus-exporter/archive/v{{bitcoind_prometheus_exporter_version}}.tar.gz"
+bitcoind_prometheus_exporter_tar_name: "bitcoin-prometheus-exporter-{{bitcoind_prometheus_exporter_version}}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind-prometheus-exporter/handlers/main.yaml	Sat May 16 17:59:15 2020 -0500
@@ -0,0 +1,5 @@
+---
+
+- name: restart service
+  become: yes
+  systemd: service="bitcoind-prometheus-exporter.service" state="restarted" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind-prometheus-exporter/tasks/main.yaml	Sat May 16 17:59:15 2020 -0500
@@ -0,0 +1,45 @@
+---
+
+- name: apt-get bitcoind-prometheus-exporter install deps
+  become: yes
+  apt: name="python3-pip"
+
+- name: pip bitcoind-prometheus-exporter install deps
+  become: yes
+  pip: name="{{item}}"
+  loop:
+    - "riprova"
+    - "prometheus_client"
+    - "python-bitcoinlib"
+
+- name: unarchive bitcoind-prometheus-exporter
+  become: yes
+  unarchive:
+    remote_src: yes
+    src: "{{bitcoind_prometheus_exporter_url}}"
+    dest: "/tmp"
+    creates: "/tmp/{{bitcoind_prometheus_exporter_tar_name}}/"
+  notify: restart service
+
+- name: install bitcoind-prometheus-exporter
+  become: yes
+  copy:
+    src: "/tmp/{{bitcoind_prometheus_exporter_tar_name}}/bitcoind-monitor.py"
+    dest: "/usr/local/bin/bitcoind-prometheus-exporter.py"
+    remote_src: yes
+    owner: "root"
+    group: "root"
+    mode: "0755"
+  changed_when: false
+
+- name: install bitcoind-prometheus-exporter service
+  become: yes
+  template:
+    src: "bitcoind-prometheus-exporter.service.j2"
+    dest: "/lib/systemd/system/bitcoind-prometheus-exporter.service"
+    mode: "0644"
+  notify: restart service
+
+- name: ensure bitcoind-prometheus-exporter service is started
+  become: yes
+  systemd: service="bitcoind-prometheus-exporter.service" enabled="yes" state="started" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind-prometheus-exporter/templates/bitcoind-prometheus-exporter.service.j2	Sat May 16 17:59:15 2020 -0500
@@ -0,0 +1,18 @@
+[Unit]
+Description=Bitcoind Prometheus Exporter
+Wants=bitcoind.service
+After=bitcoind.service
+
+[Service]
+ExecStart=/usr/local/bin/bitcoind-prometheus-exporter.py
+User=prometheus
+Environment="BITCOIN_CONF_PATH={{bitcoind_prometheus_exporter_conf}}"
+
+PrivateTmp=true
+ProtectSystem=full
+NoNewPrivileges=true
+PrivateDevices=true
+MemoryDenyWriteExecute=true
+
+[Install]
+WantedBy=multi-user.target
--- a/bitcoind/tasks/main.yaml	Thu May 14 20:19:45 2020 -0500
+++ b/bitcoind/tasks/main.yaml	Sat May 16 17:59:15 2020 -0500
@@ -28,15 +28,15 @@
 - name: create bitcoind data dir
   become: yes
   file:
-    path: "{{item}}"
+    path: "{{item.path}}"
     state: "directory"
     owner: "{{bitcoind_user}}"
     group: "{{bitcoind_user}}"
-    mode: "0770"
+    mode: "{{item.mode}}"
   loop:
-    - "{{bitcoind_data_dir}}"
-    - "{{bitcoind_log_dir}}"
-    - "{{bitcoind_conf_dir}}"
+    - { path: "{{bitcoind_data_dir}}", mode: "0750" }
+    - { path: "{{bitcoind_log_dir}}", mode: "0750" }
+    - { path: "{{bitcoind_conf_dir}}", mode: "0755" }
 
 - name: configure bitcoind
   become: yes
--- a/lnd/tasks/main.yaml	Thu May 14 20:19:45 2020 -0500
+++ b/lnd/tasks/main.yaml	Sat May 16 17:59:15 2020 -0500
@@ -38,15 +38,15 @@
 - name: create lnd data dir
   become: yes
   file:
-    path: "{{item}}"
+    path: "{{item.path}}"
     state: "directory"
     owner: "{{lnd_user}}"
     group: "{{lnd_user}}"
-    mode: "0770"
+    mode: "{{item.mode}}"
   loop:
-    - "{{lnd_data_dir}}"
-    - "{{lnd_log_dir}}"
-    - "{{lnd_conf_dir}}"
+    - { path: "{{lnd_data_dir}}", mode: "0750" }
+    - { path: "{{lnd_log_dir}}", mode: "0750" }
+    - { path: "{{lnd_conf_dir}}", mode: "0755" }
 
 - name: configure lnd
   become: yes