Added bitcoind ansible
authorLuke Hoersten <luke@hoersten.org>
Tue, 12 May 2020 19:19:36 -0500
changeset 4 9934a00b9e97
parent 3 74f60cd1440b
child 5 5873b7e583d7
Added bitcoind ansible
bitcoind/defaults/main.yaml
bitcoind/handlers/main.yaml
bitcoind/tasks/main.yaml
bitcoind/templates/bitcoin.conf.j2
bitcoind/templates/bitcoind.service.j2
lnd/templates/lnd.service.j2
node/conf/tasks/main.yaml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind/defaults/main.yaml	Tue May 12 19:19:36 2020 -0500
@@ -0,0 +1,8 @@
+---
+
+bitcoind_user: "{{node_user}}"
+bitcoind_version: "0.19.1"
+bitcoind_arch: "{{ansible_architecture}}"
+bitcoind_url: "https://bitcoin.org/bin/bitcoin-core-{{bitcoind_version}}/bitcoin-{{bitcoind_version}}-{{bitcoind_arch}}-linux-gnu.tar.gz"
+bitcoind_conf_dir: "/home/{{bitcoind_user}}/.bitcoin"
+bitcoind_enable_txindex: "1"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind/handlers/main.yaml	Tue May 12 19:19:36 2020 -0500
@@ -0,0 +1,5 @@
+---
+
+- name: restart bitcoind
+  become: yes
+  systemd: service="bitcoind.service" state="restarted" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind/tasks/main.yaml	Tue May 12 19:19:36 2020 -0500
@@ -0,0 +1,61 @@
+---
+
+- name: add bitcoind user
+  become: yes
+  user: name="{{bitcoind_user}}"
+
+- name: unarchive bitcoind
+  become: yes
+  unarchive:
+    remote_src: yes
+    src: "{{bitcoind_url}}"
+    dest: "/tmp"
+    creates: "/tmp/bitcoin-{{bitcoind_version}}/"
+
+- name: install bitcoind
+  become: yes
+  copy:
+    src: "/tmp/bitcoin-{{bitcoind_version}}/bin/{{item}}"
+    dest: "/usr/local/bin/"
+    remote_src: yes
+    owner: "root"
+    group: "root"
+    mode: "0755"
+  with_items:
+    - "bitcoind"
+    - "bitcoin-cli"
+
+- name: create bitcoind data dir
+  become: yes
+  file:
+    path: "{{item}}"
+    state: "directory"
+    owner: "{{bitcoind_user}}"
+    group: "{{bitcoind_user}}"
+    mode: "0770"
+  with_items:
+    - "{{bitcoind_data_dir}}"
+    - "{{bitcoind_log_dir}}"
+    - "{{bitcoind_conf_dir}}"
+
+- name: configure bitcoind
+  become: yes
+  template:
+    src: "bitcoin.conf.j2"
+    dest: "{{bitcoind_conf_dir}}/bitcoin.conf"
+    owner: "{{bitcoind_user}}"
+    group: "{{bitcoind_user}}"
+    mode: "0644"
+  notify: restart bitcoind
+
+- name: install bitcoind service
+  become: yes
+  template:
+    src: "bitcoind.service.j2"
+    dest: "/lib/systemd/system/bitcoind.service"
+    mode: "0644"
+  notify: restart bitcoind
+
+- name: ensure bitcoind is started
+  become: yes
+  systemd: service="bitcoind.service" enabled="yes" state="started" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind/templates/bitcoin.conf.j2	Tue May 12 19:19:36 2020 -0500
@@ -0,0 +1,16 @@
+externalip={{node_external_ip}}
+uacomment={{bitcoind_comment}}
+
+datadir={{bitcoind_data_dir}}
+logdir={{bitcoind_log_dir}}
+debug=rpc
+
+server=1
+rpcssl=1
+rpcuser={{bitcoind_rpc_user}}
+rpcpassword={{bitcoind_rpc_pass}}
+
+txindex={{bitcoind_enable_txindex}}
+
+{% for node in bitcoind_add_node %}addnode={{node}}
+{% endfor %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bitcoind/templates/bitcoind.service.j2	Tue May 12 19:19:36 2020 -0500
@@ -0,0 +1,16 @@
+[Unit]
+Description=bitcoind
+After=network.target
+
+[Service]
+ExecStart=/usr/local/bin/bitcoind
+User={{bitcoind_user}}
+
+PrivateTmp=true
+ProtectSystem=full
+NoNewPrivileges=true
+PrivateDevices=true
+MemoryDenyWriteExecute=true
+
+[Install]
+WantedBy=multi-user.target
--- a/lnd/templates/lnd.service.j2	Sun May 10 17:28:15 2020 -0500
+++ b/lnd/templates/lnd.service.j2	Tue May 12 19:19:36 2020 -0500
@@ -1,12 +1,11 @@
 [Unit]
 Description=lnd
-Wants=btcd.service
-After=btcd.service
+Wants={{lnd_bitcoin_node}}.service
+After={{lnd_bitcoin_node}}.service
 
 [Service]
 ExecStart=/usr/local/bin/lnd
 User={{lnd_user}}
-Restart=on-failure
 
 PrivateTmp=true
 ProtectSystem=full
--- a/node/conf/tasks/main.yaml	Sun May 10 17:28:15 2020 -0500
+++ b/node/conf/tasks/main.yaml	Tue May 12 19:19:36 2020 -0500
@@ -13,7 +13,7 @@
     - "{{node_log_dir}}"
     - "{{node_conf_dir}}"
 
-- name: install conf
+- name: configure node
   become: yes
   template:
     src: "{{node_conf_template}}"