Skip to content

Commit

Permalink
code refactor, add kava support, set user as variable instead of hard…
Browse files Browse the repository at this point in the history
…-coding to ubuntu
  • Loading branch information
husonghua committed Nov 20, 2021
1 parent f7b31d5 commit 0dbfc52
Show file tree
Hide file tree
Showing 27 changed files with 295 additions and 312 deletions.
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ This repo is to set up the Cosmos-based node. It currently support:

- Juno (mainnet and testnet)
- Sifchain (betanet and testnet)
- Kava (mainnet)
- Evmos (testnet)

## Summary

You run one playbook and set up a node. For example:

```bash
ansible-playbook -i inventory juno_full_setup.yml -e "target=juno_testnet"
ansible-playbook -i inventory juno.yml -e "target=juno_testnet"
```

But before you rush with this easy setup, you probably want to read on so you understand the structure of this Ansible program and all the features it offers.
Expand All @@ -24,12 +25,15 @@ First, make sure that you have a production inventory file with your confidentia
cp inventory.sample inventory
```

Needless to say, you need to update the dummy values in the inventory file. For each node, you need to update the server IP. While you are free to keep the default, you might also want to update:
Needless to say, you need to update the dummy values in the inventory file. For each node, you need to update the server IP, validator_name and log_name (log_name is optional if you do not install Promtail). While you are free to keep the default, you might also want to update:

1. ansible_user: The sample file assumes `ubuntu`.
1. ansible_user: The sample file assumes `ubuntu`, but feel free to use other user name. This user need sudo privilege.
2. ansible_port: The sample file assumes `22`. But if you are like me, you will have a different ssh port other than `22` to avoid port sniffing.
3. ansible_ssh_private_key_file: The sample file assumes `~/.ssh/id_rsa`, but you might have a different key location.
4. log_monitor: Enter your monitor server IP. It is most likely a private IP address if you use a firewall around your private virtual cloud (VPC).
4. path: This is to make sure that the ansible_user can access the `go` executable. If your ansible_user is not `ubuntu`, you need to update it.
5. node_exporter: Default is `true`. Change it to `false` if you do not want to install node_exporter
6. promtail: Default is `true`. Change it to `false` if you do not want to install promtail
7. log_monitor: Enter your monitor server IP. It is most likely a private IP address if you use a firewall around your private virtual cloud (VPC). You do not need this if you do not install promtail

It is beyond the scope of this guide to help you create a sudo user, alternate ssh port, create a private key, install Ansible on your machine, etc. You can do a quick online search and find the answers. In my experience, Digital Ocean have some quality guides on these topics. Stack Overflow can help you trouble-shoot if you are stuck.

Expand All @@ -43,14 +47,30 @@ The basic cluster structure is:

The structure allows you to target `vars` to each node, or a group cluster, or the whole cluster. Make sure that you are familiar with the files in the `group_vars` folder. They follow this clustered structure closely.

## Main Playbook
## Playbooks

The key Ansible playbook is `xxxxx_full_setup.yml` files. It will set up a fresh node from scratch. For example:
The key Ansible playbook is `<chain>.yml` files. It will set up a fresh node from scratch. For example:

```bash
ansible-playbook -i inventory sifchain_full_setup.yml -e "target=sifchain_betanet"
ansible-playbook -i inventory sifchain.yml -e "target=sifchain_betanet"
```

Playbooks are:

| Playbook | Description |
| -------------- | ------------------------------------------------------------------------------------ |
| `prepare.yml ` | Prepare the server with node_exporter, promtail, go, cosmovisor, and firewall rules |
| `juno.yml` | Set up Juno node. It include the general `prepare` task and `juno` specific task |
| `sifchain.yml` | Set up Juno node. It include the general `prepare` task and `sifchain` specific task |
| `kava.yml` | Set up Juno node. It include the general `prepare` task and `kava` specific task |

## Additional Info

When you install a node that has upgrades in the past, you can either sync from Block 1, or use a snapshot to time travel. We strongly recommend snapshots, which will save you time of syncing and debugging. Here are a list of trusted snapshot providers. Do your own research and make sure that you can trust the snapshot providers

- Various chains: https://www.chainlayer.io/quicksync/
- Sifchain: see https://github.com/Sifchain/sifchain-validators/blob/master/docs/setup/standalone/manual.md

## Some Useful Commands

block height
Expand Down
5 changes: 5 additions & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# node_exporter
node_exporter_version: '1.2.2'
node_exporter_checksum: '344bd4c0bbd66ff78f14486ec48b89c248139cdd485e992583ea30e89e0e5390'

# promtail
promtail_version: '2.4.1'
promtail_checksum: 978391a174e71cfef444ab9dc012f95d5d7eae0d682eaf1da2ea18f793452031

# go
go_version: '1.17.1'
16 changes: 1 addition & 15 deletions group_vars/evmos_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
validator_name: polkachu-evmos-testnet
log_name: evmos_testnet
network: evmos
folder: '.evmosd'
daemon: evmosd
Expand All @@ -9,16 +7,4 @@ genesis: 'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni/ge
repo: https://github.com/CosmosContracts/juno
minimum_has_price: '0.025ujunox'
peers: 'be7593d1d2cae15a574537f9107f525200824767@194.163.187.94:26656,78605eed3018a74d9c8c3a912cd8e6d5c9a9ca4b@65.21.232.149:26726,3bd90caf48ddd2d6b290550ecccd63348fc51da0@95.217.107.96:26658,f8da50943569f160854ac21c9ffb46fb4ff7bc0d@144.217.252.197:26626,1c4c38243893889a17fd3e677999f896b2b18586@95.217.35.111:26666,0e4dec8dd2cb74277bae3a9e7f1816603e97ce60@161.97.178.48:26656,3e7b138c766dc6da32decca8665da1afb2b6bb88@207.244.249.17:26656,5502b008356087cb689211bb3c4285b7ce7f6571@95.217.154.12:26656,8227d17c3cf123108c69bf671295e5fb22d9beb3@161.97.115.68:26656,56de4d8fe7421f5a4fb6ba75b20d749be3eecf22@95.217.84.54:26656,06e3dfce2d729250e810bd5605ad7f05f3b1fc2c@75.119.155.119:26656,7cb1576a6ed3dbdc62bc30908ff7d7e910c5b08f@78.46.52.20:46656,5502b008356087cb689211bb3c4285b7ce7f6571@95.217.154.12:26656,5576b0160761fe81ccdf88e06031a01bc8643d51@195.201.108.97:24656,13e850d14610f966de38fc2f925f6dc35c7f4bf4@176.9.60.27:26656'
seed: 'c36cec90ded95d162b85f8ecd00ecd7c8849ca75@arsiamons.seed.evmos.org:26656,3787335176bbb91bf14a67724ebe0f0940ca5afb@evmos-seed.artifact-staking.io:26656,faa31510d9280e74e7f2e767a62023bd5c896c27@evmos-testnet.mercury-nodes.net:29447'
# evmosd tx staking create-validator \
# --amount=1000000000000aphoton \
# --pubkey=$(evmosd tendermint show-validator) \
# --moniker="polkachu-evomos-testnet" \
# --chain-id= evmos_9000-2 \
# --commission-rate="0.10" \
# --commission-max-rate="0.20" \
# --commission-max-change-rate="0.01" \
# --min-self-delegation="1000000" \
# --gas="auto" \
# --gas-prices="0.025aphoton" \
# --from=polkachu
seeds: 'c36cec90ded95d162b85f8ecd00ecd7c8849ca75@arsiamons.seed.evmos.org:26656,3787335176bbb91bf14a67724ebe0f0940ca5afb@evmos-seed.artifact-staking.io:26656,faa31510d9280e74e7f2e767a62023bd5c896c27@evmos-testnet.mercury-nodes.net:29447'
6 changes: 2 additions & 4 deletions group_vars/juno_mainnet.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
validator_name: polkachu-juno-mainnet
log_name: juno_mainnet
network: juno
folder: '.juno'
daemon: junod
chain_id: juno-1
node_version: v1.0.0
genesis: 'https://raw.githubusercontent.com/CosmosContracts/mainnet/main/juno-1/genesis.json'
repo: https://github.com/CosmosContracts/juno
minimum_has_price: '0.025ujuno'
genesis: 'https://raw.githubusercontent.com/CosmosContracts/mainnet/main/juno-1/genesis.json'
peers: 'c12726cfc959b54c90c0831216bab970645b536c@18.223.79.98:26656,b1f46f1a1955fc773d3b73180179b0e0a07adce1@162.55.244.250:39656,7f593757c0cde8972ce929381d8ac8e446837811@178.18.255.244:26656,7b22dfc605989d66b89d2dfe118d799ea5abc2f0@167.99.210.65:26656,4bd9cac019775047d27f9b9cea66b25270ab497d@137.184.7.164:26656,bd822a8057902fbc80fd9135e335f0dfefa32342@65.21.202.159:38656,15827c6c13f919e4d9c11bcca23dff4e3e79b1b8@51.38.52.210:38656,e665df28999b2b7b40cff2fe4030682c380bf294@188.40.106.109:38656,92804ce50c85ff4c7cf149d347dd880fc3735bf4@34.94.231.154:26656,795ed214b8354e8468f46d1bbbf6e128a88fe3bd@34.127.19.222:26656,ea9c1ac0e91639b2c7957d9604655e2263abe4e1@185.181.103.136:26656'
minimum_has_price: '0.025ujuno'
6 changes: 2 additions & 4 deletions group_vars/juno_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
validator_name: polkachu-juno-testnet
log_name: juno_testnet
network: juno
folder: '.juno'
daemon: junod
chain_id: uni
node_version: v1.0.0
genesis: 'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni/genesis.json'
repo: https://github.com/CosmosContracts/juno
minimum_has_price: '0.025ujunox'
genesis: 'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni/genesis.json'
peers: 'b2ef97b03c049c39a975b7845abe40fb3e48ee36@216.238.71.243:26656,34e9b3698c0a0fc7e5a8c16dc63b4d913c496c2d@206.189.151.85:26656,7ff7fd0119b104f659810ece82e9cefe2819bb33@128.199.97.8:26656,a1d3e3e6615f8eded91b012c69edb6b1bb0f5e42@161.97.187.234:26656,cdfdd1735bad77c49290e9485b8eb49fbd61ca4d@178.128.36.63:26656,4a91597dfe3ec715bbf6def225066fbb6ad86cfe@207.180.204.112:36656,15bbe91a29693284c4c13138550ea0b6a34f9c42@137.184.11.214:26656,b5377aa9885c69e154820d19be6c87c3d3c34d14@65.108.85.61:26656'
minimum_gas_price: '0.025ujunox'
10 changes: 10 additions & 0 deletions group_vars/kava_mainnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
network: kava
folder: '.kvd'
daemon: kvd
chain_id: kava-8
node_version: v0.15.1
repo: https://github.com/kava-labs/kava
genesis: 'https://kava-genesis-files.s3.amazonaws.com/kava-8-genesis-migrated-from-block-1878508.json'
peers: '12ce13dc36f142f0148dfdd126fbc269a6f30a16@34.200.56.118:26656,bf06dc58fe2b63eaa9ebb3a10518c57459248ed4@54.80.39.137:26656,3805abc1198b970f240948cfe78d0162fab87c5d@44.198.20.70:26656,5870640558f4c6b4d4c9fe98848a63a84ade1991@18.232.243.20:26656,11f965df6fb3091e0fa3a1e4c129ff697939b827@54.185.38.14:26656,00367117989dce8ce84fd22a1967680b604eef66@13.56.154.100:26656,e3ce1ea109ce541e7e45e448f200f5fc6c0b1b4d@54.219.33.62:26656,f4391903ae4d8300e22103358a205237fba108c4@13.209.173.243:26656,c6d5a2c7f321bb8abf52a342d52195089c0b4e61@3.141.176.20:26656,9b278bbf2c0308eb2a4a4f72e6d0d63cb19ad11d@141.94.101.216:26656,bd6d7005a588277b4306abc67c6605586971cd67@116.202.82.201:50056,7b9e23a50afe59382affe474ecfdba2aad5757f1@34.66.96.15:26656,e0768d1b55c5b1390bc78f8976415381d0ac4da5@34.82.232.135:26656,d3658cb9c63cf43b0c707401649809a6007a7c12@94.130.67.43:26656,4f4b567edcc417ff5ff21d26fb56237e60da81b3@132.145.126.161:26656,508d7ec33c7f3c9c479ca9b845cadbbefee670f7@95.216.16.245:21656,13a9ca027c84938525bbd042b78c64d08864e6b9@136.244.95.119:26656,bcb2f02c7fd6c649ac45c8f2a87482310ebe1ae5@45.76.90.130:26656,1074a6f31d2c7df6e21ce0e574a5cb75f1763be1@13.56.31.21:26656,1291ef230910953545fb3d83c4e989578da978a1@35.157.56.248:26656,ad62204afa2a3e13163f83d87e9b1e7a2ca2b789@213.159.16.48:26656'
minimum_gas_price: '0.001ukava'
seeds: '2c11fb480bb842e2fc181ab57c11baba0131dca3@44.196.226.19:26656'
5 changes: 2 additions & 3 deletions group_vars/sifchain_betanet.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
validator_name: polkachu-sifchain-betanet
log_name: sifchain_betanet
network: sifnoded
folder: '.sifnoded'
daemon: sifnoded
chain_id: sifchain-1
node_version: master
genesis: 'https://raw.githubusercontent.com/Sifchain/networks/master/betanet/sifchain-1/genesis.json.gz'
repo: https://github.com/Sifchain/sifnode.git
genesis: 'https://raw.githubusercontent.com/Sifchain/networks/master/betanet/sifchain-1/genesis.json.gz'
peers: '0d4981bdaf4d5d73bad00af3b1fa9d699e4d3bc0@44.235.108.41:26656,bcc2d07a14a8a0b3aa202e9ac106dec0bef91fda@13.55.247.60:26656,663dec65b754aceef5fcccb864048305208e7eb2@34.248.110.88:26656,0120f0a48e7e81cc98829ef4f5b39480f11ecd5a@52.76.185.17:26656,6535497f0152293d773108774a705b86c2249a9c@44.238.121.65:26656,fdf5cffc2b20a20fab954d3b6785e9c382762d14@34.255.133.248:26656,8c240f71f9e060277ce18dc09d82d3bbb05d1972@13.211.43.177:26656,9fbcb6bd5a7f20a716564157c4f6296d2faf5f64@18.138.208.95:26656'
9 changes: 5 additions & 4 deletions group_vars/sifchain_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
validator_name: polkachu-sifchain-testnet
log_name: sifchain_testnet

chain_type: testnet
network: sifnoded
folder: '.sifnoded'
daemon: sifnoded
chain_id: sifchain-testnet-1
node_version: testnet-0.9.0
repo: https://github.com/Sifchain/sifnode.git
genesis: 'https://raw.githubusercontent.com/Sifchain/networks/master/testnet/sifchain-testnet-1/genesis.json.gz'
peers: 'b4caebe07ab25126e4e6053bf955833198f18ed0@54.216.30.38:26656,b6f113a30e7019b034e8b31cd2541aebebaacb60@54.66.212.111:26656,ffcc2fab592d512eca7f903fd494d85a93e19cfe@122.248.219.121:26656,a2864737f01d3977211e2ea624dd348595dd4f73@3.222.8.87:26656'
22 changes: 15 additions & 7 deletions inventory.sample
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
[sifchain_betanet]
10.0.0.1
10.0.0.1 validator_name=polkachu-sifchain-betanet log_name=sifchain_betanet

[sifchain_testnet]
10.0.0.2
10.0.0.2 validator_name=polkachu-sifchain-testnet log_name=sifchain_testnet

[juno_testnet]
10.0.0.2
10.0.0.2 validator_name=polkachu-juno-testnet log_name=juno_testnet

[juno_mainnet]
10.0.0.3
10.0.0.3 validator_name=polkachu-juno-mainnet log_name=juno_mainnet

[evmos_testnet]
10.0.0.4
10.0.0.4 validator_name=polkachu-evmos-testnet log_name=evmos_testnet

[kava_mainnet]
10.0.0.5 validator_name=polkachu-kava-mainnet log_name=kava_mainnet

[sifchain:children]
sifchain_betanet
Expand All @@ -24,9 +27,14 @@ juno_testnet
[evmos:children]
evmos_testnet

[kava:children]
kava_mainnet

[all:vars]
ansible_user=ubuntu
ansible_port=22
ansible_ssh_private_key_file="~/.ssh/id_rsa"
log_monitor=10.0.0.100
path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin:/home/ubuntu/go/bin"
path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin:/home/ubuntu/go/bin"
node_exporter=true
promtail=true
log_monitor=10.0.0.100
6 changes: 4 additions & 2 deletions juno_full_setup.yml → juno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
roles:
- prepare

- name: Install Juno
- name: Install node
hosts: '{{ target }}'
gather_facts: false
roles:
- juno
- standard_node_installation
- initialize_juno
- launch_node
15 changes: 15 additions & 0 deletions kava.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Prepare
hosts: '{{ target }}'
become: true
gather_facts: false
roles:
- prepare

- name: Install node
hosts: '{{ target }}'
gather_facts: false
roles:
- standard_node_installation
- initialize_kava
- launch_node
32 changes: 32 additions & 0 deletions roles/initialize_juno/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: Initialize Node
command: '{{ daemon }} init {{ validator_name }} --chain-id {{ chain_id }} -o'
environment:
PATH: '{{ path }}'

- name: Update minimum gas price on config file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/app.toml'
regexp: 'minimum-gas-prices '
line: 'minimum-gas-prices = "{{ minimum_gas_price }}"'
state: present

- name: Update the config.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/config.toml'
regexp: 'persistent_peers = ""'
line: 'persistent_peers = "{{ peers }}"'
state: present

- name: Download genesis file
get_url:
url: '{{ genesis }}'
dest: '/home/{{ ansible_user }}/{{ folder }}/config/genesis.json'
mode: '0644'

- name: Enable prometheus on the config.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/config.toml'
regexp: 'prometheus = false'
line: 'prometheus = true'
state: present
33 changes: 33 additions & 0 deletions roles/initialize_kava/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Initialize Node
command: '{{ daemon }} init {{ validator_name }} --chain-id {{ chain_id }} -o'
environment:
PATH: '{{ path }}'

- name: Update app.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/app.toml'
regexp: 'minimum-gas-prices '
line: 'minimum-gas-prices = "{{ minimum_gas_price }}"'
state: present

- name: Update persistent peers on the config.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/config.toml'
regexp: 'persistent_peers = ""'
line: 'persistent_peers = "{{ peers }}"'
state: present

- name: Update seeds on the config.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/config.toml'
regexp: 'seeds = ""'
line: 'seeds = "{{ seeds }}"'
state: present

- name: Download genesis file
get_url:
url: '{{ genesis }}'
dest: '/home/{{ ansible_user }}/{{ folder }}/config/genesis.json'
mode: '0644'
force: true
27 changes: 27 additions & 0 deletions roles/initialize_sifchain/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Initialize Node
command: '{{ daemon }} init {{ validator_name }} --chain-id {{ chain_id }} -o'
environment:
PATH: '{{ path }}'

- name: Update the config.toml file
lineinfile:
path: '/home/{{ ansible_user }}/.{{ network }}/config/config.toml'
regexp: 'persistent_peers = ""'
line: 'persistent_peers = "{{ peers }}"'
state: present

- name: Download genesis file
get_url:
url: '{{ genesis }}'
dest: '/tmp/genesis.json.gz'
mode: '0700'

- name: unarchive genesis file
shell: 'gunzip /tmp/genesis.json.gz -f'

- name: copy the genesis file
copy:
remote_src: true
src: /tmp/genesis.json
dest: /home/{{ ansible_user }}/.sifnoded/config
Loading

0 comments on commit 0dbfc52

Please sign in to comment.