Skip to content

Instantly share code, notes, and snippets.

@goodc0re
Created September 22, 2021 07:35
Show Gist options
  • Save goodc0re/6ece2272b2c5b9fd93ca9791735839c8 to your computer and use it in GitHub Desktop.
Save goodc0re/6ece2272b2c5b9fd93ca9791735839c8 to your computer and use it in GitHub Desktop.
Ansible playbook to update a dash masternode without dashman on Ubuntu
# update_dash_mns.yml
---
- hosts: dash_masternodes
vars_files: vault.yml
become: yes
become_method: sudo
tasks:
- name: 'Ensure dashd job is no longer present. Removes any job that is prefixed by "#Ansible: dashd" from the crontab'
ansible.builtin.cron:
name: "dashd"
state: absent
- name: Download dash binary
become: no
get_url:
url: https://github.com/dashpay/dash/releases/download/v0.17.0.3/dashcore-0.17.0.3-x86_64-linux-gnu.tar.gz
dest: /tmp
mode: 0440
- name: Stop dashd
become: no
command: ./dash-cli stop
args:
chdir: /home/dash/.dashcore
- name: Unarchive dash binary
become: no
unarchive:
src: /tmp/dashcore-0.17.0.3-x86_64-linux-gnu.tar.gz
dest: /tmp/
remote_src: yes
- name: Copy dashd
ansible.builtin.copy:
src: /tmp/dashcore-0.17.0/bin/dashd
dest: /home/dash/.dashcore/
owner: dash
group: dash
mode: u=rwx,g=rx,o=rx
- name: Copy dash-cli
ansible.builtin.copy:
src: /tmp/dashcore-0.17.0/bin/dash-cli
dest: /home/dash/.dashcore/
owner: dash
group: dash
mode: u=rwx,g=rx,o=rx
- name: Delete downloaded archive
become: no
file:
path: /tmp/dashcore-0.17.0.3-x86_64-linux-gnu.tar.gz
state: absent
- name: Update all packages on a Debian/Ubuntu
apt:
update_cache: yes
upgrade: dist
- name: Check if a reboot is required
register: reboot_required_file
stat: path=/var/run/reboot-required get_md5=no
- name: Reboot box if kernel/libs updated and requested by the system
shell: sleep 10 && /sbin/shutdown -r now 'Rebooting box to update system libs/kernel as needed'
args:
removes: /var/run/reboot-required
async: 300
poll: 0
ignore_errors: true
when: reboot_required_file.stat.exists == true
- name: Wait for system to become reachable again
wait_for_connection:
delay: 60
timeout: 300
when: reboot_required_file.stat.exists == true
- name: Verify new update (optional)
command: uname -mrs
register: uname_result
when: reboot_required_file.stat.exists == true
- name: Display new kernel version
debug:
var: uname_result.stdout_lines
when: reboot_required_file.stat.exists == true
- name: Restart dashd
become: no
command: ~/.dashcore/dashd
args:
chdir: /home/dash/.dashcore/
- name: Ensure a job that runs at 2 and 5 exists. Creates an entry like "0 5,2 * * ls -alh > /dev/null"
ansible.builtin.cron:
name: "dashd"
job: "pidof dashd || ~/.dashcore/dashd"
@goodc0re
Copy link
Author

Refer to the ansible documentation at https://docs.ansible.com/ansible/latest/user_guide/index.html#getting-started

This playbook requires:

  • ssh keys uploaded to the masternode for ansible to log in
  • ansible to be installed on the controlling machine (can be your local machine or another server)
  • a hosts file on the controlling machine that specifies the IP addresses, ssh ports and login usernames of the masternodes
  • an ansible vault file on the controlling machine with the encrypted passwords that are needed for sudo

Command I use to run this playbook with ansible:

$ ansible-playbook -i hosts --ask-vault-pass update_dash_mns.yml -vv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment