Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
Signed-off-by: Dylan Schultz <[email protected]>
  • Loading branch information
dylanschultzie committed Sep 7, 2022
1 parent 84c221e commit de656cb
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
inventory.yml
group_vars/mainnets/*
group_vars/testnets/*
keys/*
hostbin/*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Functions
nam = $(firstword $(subst :, ,$1))
val = $(or $(word 2,$(subst ": ", , $1)),$(value 2))
hostarch:=linux_amd64
hostarch:=darwin_arm64
tmphorcruxVer := $(shell grep horcrux_version group_vars/all.yml)
tmphorcruxRepo := $(shell grep horcrux_repo group_vars/all.yml)
horcruxVer = $(subst $\',,$(call val,$(tmphorcruxVer)))
Expand Down
11 changes: 11 additions & 0 deletions group_vars/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
network:
chain_id: ''
sentries:
- '1.0.2.1:17659'
- '1.2.3.4:12859'

signer_port: 053
rpc_timeout: "750ms"
threshold: 2
shares: 3
2 changes: 0 additions & 2 deletions group_vars/mainnets/example.yml

This file was deleted.

4 changes: 3 additions & 1 deletion horcrux.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
- name: Install node
hosts: '{{ target }}'
hosts: all
become: true
gather_facts: false
vars_files:
- '{{ var_file }}'
roles:
- horcrux_install
49 changes: 38 additions & 11 deletions roles/horcrux_install/tasks/configure_horcrux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
owner: '{{ horcrux_user }}'
group: '{{ horcrux_user }}'
state: directory
path: '{{ horcrux_dir }}'
path: '{{ horcrux_dir }}/state'
mode: '0750'

- name: Create state files
Expand All @@ -19,23 +19,50 @@
- priv_validator_state.json
- share_sign_state.json

- name: Copy horcrux service file
become: true
template:
src: 'horcrux.service.j2'
dest: '/etc/systemd/system/{{ service_file }}'
owner: root
group: root
mode: 600

- name: Generate private keys
become: false
local_action: command make genkeys
run_once: True

- name: Find local key share
delegate_to: localhost
become: no
stat:
path: "{{ playbook_dir }}/keys/private_share_{{ my_share }}.json"
register: has_share

- name: Copy keys
copy:
src: "keys/private_share_{{ signorder }}.json"
src: "keys/private_share_{{ my_share }}.json"
dest: "{{ horcrux_dir }}/share.json"
owner: "{{ horcrux_user }}"
group: "{{ horcrux_user }}"
mode: '0400'
when: has_share.stat.isreg is defined and has_share.stat.isreg

- name: Copy config
template:
backup: yes
src: config.yml
dest: "{{ horcrux_dir }}/config.yml"
owner: "{{ horcrux_user }}"
group: "{{ horcrux_user }}"
mode: '0644'
tags: configs

- name: Copy horcrux service file
become: true
template:
src: 'horcrux.service.j2'
dest: '/etc/systemd/system/{{ service_file }}'
owner: root
group: root
mode: 600
register: systemdunit

- name: Enable systemd unit
systemd:
daemon_reload: yes
name: "{{ service_file }}"
enabled: yes
when: systemdunit.changed
13 changes: 12 additions & 1 deletion roles/horcrux_install/tasks/create_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
- name: Create horcrux user
user:
name: '{{ horcrux_user }}'
password: '!'
home: '{{ horcrux_home }}'
password: '{{ horcrux_password }}'
shell: /bin/bash
password_lock: true

- name: Set authorized keys
authorized_key:
user: "{{ horcrux_user }}"
key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"

- name: Allow sudo for administrator
copy:
content: '{{ horcrux_user }} ALL=(ALL:ALL) NOPASSWD: ALL'
dest: '/etc/sudoers.d/{{ horcrux_user }}'
8 changes: 4 additions & 4 deletions roles/horcrux_install/tasks/install_horcrux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
- name: Clone horcrux repo
git:
repo: '{{ horcrux_repo }}'
dest: '{{ horcrux_dir }}/horcrux'
dest: '{{ horcrux_home }}/horcrux'
version: "{{ horcrux_version }}"
update: yes

- name: Install horcrux
command: '{{ item }}'
args:
chdir: '{{ horcrux_dir }}/horcrux'
chdir: '{{ horcrux_home }}/horcrux'
with_items:
- 'make install'
environment:
PATH: '{{ path }}'
GOPATH: '{{ horcrux_dir }}/go'
GOPATH: '{{ horcrux_home }}/go'

- name: Copy .profile
template:
src: 'profile.j2'
dest: '{{ horcrux_dir }}/.profile'
dest: '{{ horcrux_home }}/.profile'
owner: '{{ horcrux_user }}'
group: '{{ horcrux_user }}'
mode: '0600'
2 changes: 0 additions & 2 deletions roles/horcrux_install/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import_tasks: create_user.yml

- name: Install horcrux
become_user: {{ horcrux_user }}
import_tasks: install_horcrux.yml

- name: Configure horcrux
become_user: {{ horcrux_user }}
import_tasks: configure_horcrux.yml
4 changes: 2 additions & 2 deletions roles/horcrux_install/templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ chain-id: {{ chain_id }}
cosigner:
threshold: {{ threshold }}
shares: {{ shares }}
p2p-listen: tcp://{{ ansible_wg0.ipv4.address }}:2{{ signer_port }}
p2p-listen: tcp://{{ ansible_host }}:2{{ signer_port }}
peers:
{% for peer in horcrux_peers %}
{% if peer.share_id != my_share %}
- share-id: {{ peer.share_id }}
p2p-addr: {{ peer.p2p_addr }}
p2p-addr: tcp://{{ peer.p2p_addr }}:2{{ signer_port }}
{% endif %}
{% endfor %}
rpc-timeout: {{ rpc_timeout }}
Expand Down
2 changes: 1 addition & 1 deletion roles/horcrux_install/templates/horcrux.service.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description={{ chain_id }} Signer node {{ signorder }}
Description={{ chain_id }} Signer node {{ my_share }}
After=network.target

[Service]
Expand Down

0 comments on commit de656cb

Please sign in to comment.