Skip to content

Commit

Permalink
test version cookie fir idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
mvrahden committed Apr 22, 2024
1 parent 44d0ae1 commit a5ff23d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
- name: Bitcoind | Set current version fact
ansible.builtin.set_fact:
_bitcoind_change_version: false # default

- name: Bitcoind | Ensure dependencies are installed
ansible.builtin.apt:
update_cache: true
Expand Down Expand Up @@ -41,6 +45,23 @@
group: "{{ bitcoind_group }}"
mode: "0755"

- name: "Bitcoind | Load version cookie file"
slurp:
src: "{{ bitcoind_data_dir }}/.bitcoind.version"
register: _bitcoind_version_cookie_file
ignore_errors: true

- name: "Bitcoind | Get current version from cookie"
set_fact:
_bitcoind_change_version: "{{ _bitcoind_version_cookie_file['content'] | b64decode | regex_findall('(\\d+\\.\\d+)') | first }} is version({{ bitcoind_version }}, '!=' , strict=true)"
when: "not _bitcoind_version_cookie_file.failed"

- debug:
msg: "{{ _bitcoind_version_cookie_file }}"
when: "not _bitcoind_version_cookie_file.failed"
- debug:
msg: "{{ _bitcoind_change_version }}"

- name: "Bitcoind | Download SHA256SUMS for Bitcoin v{{ bitcoind_version }} into '/tmp/SHA256SUMS'"
ansible.builtin.get_url:
url: https://bitcoincore.org/bin/bitcoin-core-{{ bitcoind_version }}/SHA256SUMS
Expand Down Expand Up @@ -80,6 +101,7 @@
name: bitcoind-{{ bitcoind_network }}.service
state: stopped
register: _bitcoind_systemd_stop
when: _bitcoind_change_version
failed_when:
- _bitcoind_systemd_stop.failed
- "'Could not find the requested service' not in _bitcoind_systemd_stop.msg"
Expand Down Expand Up @@ -131,3 +153,8 @@
daemon_reload: true
enabled: true
state: started

- name: "Bitcoind | Ensure version cookie file set"
ansible.builtin.template:
src: .bitcoind.version.j2
dest: "{{ bitcoind_data_dir }}/.bitcoind.version"
2 changes: 2 additions & 0 deletions templates/.bitcoind.version.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## This file is managed by mvrahden/bitcoind-ansible.
{{ bitcoind_version }}

0 comments on commit a5ff23d

Please sign in to comment.