diff --git a/ansible/README.md b/ansible/README.md index 0ce68cad6..53bc15e11 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -9,9 +9,10 @@ The playbooks in this folder run [ansible](http://www.ansible.com/) roles which: -* install and configure tendermint -* install and configure basecoin -* start/stop tendermint and basecoin +* install tendermint +* install basecoin +* configure tendermint and basecoin +* start/stop tendermint and basecoin and reset their configuration ## Prerequisites @@ -27,19 +28,19 @@ Head over to the [Terraform folder](https://github.com/tendermint/tools) for a d Optional for Amazon AWS instances: * Amazon AWS API access key ID and secret access key. -The cloud inventory scripts come from the ansible team at https://github.com/ansible/ansible. You can get the latest version from the contrib/inventory folder. +The cloud inventory scripts come from the ansible team at their [GitHub](https://github.com/ansible/ansible) page. You can get the latest version from the contrib/inventory folder. ## Ansible setup Ansible requires a "command machine" or "local machine" or "orchestrator machine" to run on. This can be your laptop or any machine that runs linux. (It does not have to be part of the cloud network that hosts your servers.) -Note: The below commands use the Ubuntu/Debian `apt-get` command. To make it compatible with RedHat/CentOS, replace it with `yum`. +Note: All the below commands use the Ubuntu/Debian `apt-get` command. To make it compatible with RedHat/CentOS, replace it with `yum`. ``` sudo apt-get install ansible ``` -To make life easier, you can start an SSH Agent and load your SSH key(s). This way ansible will have an uninterrupted way of connecting to tour servers. +To make life easier, you can start an SSH Agent and load your SSH key(s). This way ansible will have an uninterrupted way of connecting to your servers. ``` ssh-agent > ~/.ssh/ssh.env @@ -84,7 +85,7 @@ AWS_SECRET_ACCESS_KEY='' python -u inventory/ec2.py --refresh-cache 1> /dev/null ``` -Note you don't need the access key and secret key set, if you are running ansible on an Amazon AMI instance with the proper IAM permissions set. +Note: you don't need the access key and secret key set, if you are running ansible on an Amazon AMI instance with the proper IAM permissions set. ## Running the playbook @@ -111,7 +112,7 @@ ansible-playbook -i inventory/ec2.py install.yml ### Installing custom versions -By default ansible installs the tendermint and basecoin binary versions defined in its [default variables](#Default variables). If you built your own version of the binaries, you can tell ansible to install that instead. +By default ansible installs the tendermint and basecoin binary versions defined in its [default variables](#Default variables). If you build your own version of the binaries, you can tell ansible to install that instead. ``` GOPATH="" @@ -123,12 +124,28 @@ TF_VAR_TESTNET_NAME="testnet-servers" ansible-playbook -i inventory/digital_ocean.py install.yml -e tendermint_release_install=false -e basecoin_release_install=false ``` -## Starting the servers +Alternatively you can change the variable settings in `group_vars/all`. -To be continued... +## Other commands and roles + +There are few extra playbooks to make life easier managing your servers. + +* install.yml - the all-in-one playbook to install and configure tendermint + basecoin +* reset.yml - stop the application, reset the configuration (blockchain), then start the application again +* stop.yml - stop the application +* start.yml - start the application +* restart.yml - restart the application + +The roles are self-sufficient under the `roles/` folder. + +* install-tendermint - install the tendermint application. It can install release packages or custom-compiled binaries. +* install-basecoin - install the basecoin application. It can install release packages or custom-compiled binaries. +* cleanupconfig - delete all tendermint and basecoin configuration. +* config - configure tendermint and basecoin +* stop - stop the application. +* start - start the application. ## Default variables - -To be continued... +Default variables are documented under `group_vars/all`. diff --git a/ansible/Vagrantfile b/ansible/Vagrantfile index 83ad01595..117d7e18d 100644 --- a/ansible/Vagrantfile +++ b/ansible/Vagrantfile @@ -14,7 +14,5 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provision :ansible do |ansible| ansible.playbook = "install.yml" - ansible.verbose = 'vv' - ansible.sudo = true end end diff --git a/ansible/group_vars/all b/ansible/group_vars/all index 6fdc88ed7..61b08ab20 100644 --- a/ansible/group_vars/all +++ b/ansible/group_vars/all @@ -1,45 +1,77 @@ --- -#tendermint_release_install: true -#tendermint_version: 0.10.0-rc1 -#tendermint_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/tendermint/v{{tendermint_version}}/tendermint_{{tendermint_version}}_linux_amd64.zip" +### +### Tendermint installation +### -##If tendermint_release_install == false, copy the binary from here +## This file shows and sets the global defaults for the role variables. + +## tendermint_release_install indicates if the install-tendermint role should install a release version or a private build of the tendermint app +## +#tendermint_release_install: true + +## tendermint_download stores the link to the specific tendermint release to install +## +#tendermint_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/tendermint/v0.10.0-rc1/tendermint_0.10.0-rc1_linux_amd64.zip" + +## tendermint_binary stores the path to a private tendermint binary to install +## #tendermint_binary: "{{ lookup('env','GOPATH') | default('') }}/bin/tendermint" +## Details of the linux user the tendermint app uses +## #tendermint_user: tendermint #tendermint_group: tendermint - -## Upstart start/stop conditions can vary by distribution and environment -#tendermint_upstart_start_on: start on runlevel [345] -#tendermint_upstart_stop_on: stop on runlevel [!345] - #tendermint_home: /var/lib/tendermint + +## tendermint_log_file stores the path to the tendermint application log +## #tendermint_log_file: /var/log/tendermint.log -#basecoin_release_install: true -#basecoin_version: 0.4.0 -#basecoin_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/basecoin/v{{basecoin_version}}/basecoin_{{basecoin_version}}_linux_amd64.zip" +### +### Basecoin installation +### -##If basecoin_release_install == false, copy the binary from here +## basecoin_release_install indicates if the install-basecoin role should install a release version or a private build of the basecoin app +## +#basecoin_release_install: true + +## basecoin_download stores the link to the specific basecoin release to install +## +#basecoin_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/basecoin/v0.4.0/basecoin_0.4.0_linux_amd64.zip" + +## basecoin_binary stores the path to a private basecoin binary to install +## #basecoin_binary: "{{ lookup('env','GOPATH') | default('') }}/bin/basecoin" +## Details of the linux user the basecoin app uses +## #basecoin_user: basecoin #basecoin_group: basecoin - -## Upstart start/stop conditions can vary by distribution and environment -#basecoin_upstart_start_on: start on runlevel [345] -#basecoin_upstart_stop_on: stop on runlevel [!345] - #basecoin_home: /var/lib/basecoin + +## basecoin_log_file stores the path to the basecoin application log +## #basecoin_log_file: /var/log/basecoin.log +### +### Basecoin configuration +### + +## basecoin_inprocess indicates if basecoin should run tendermint in-process +## #basecoin_inprocess: false -#Used by the config role -#testnet_name: test-chain +### +### Development settings +### +## Used by the config role to find seed IPs and public keys and set the chain_id in genesis.json and config.toml +## +#testnet_name: testnet1 -basecoin_inprocess: false -tendermint_release_install: false -basecoin_release_install: false +## Used by the config role to add a lot of mycoins to wallet 0x1B1BE55F969F54064628A63B9559E7C21C925165. +## Use /usr/share/basecoin/dev-keys/key.json to access them. +## Tendermint data has to be cleared when setting or resetting this key. +## +#dev_money: false diff --git a/ansible/reinit.yml b/ansible/reinit.yml deleted file mode 100644 index de3263bb1..000000000 --- a/ansible/reinit.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- - -- hosts: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}" - user: root - roles: - - cleanupconfig - - { role: config, testnet_name: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}" } - diff --git a/ansible/reset.yml b/ansible/reset.yml index b5f92b4eb..a49f9d3d4 100644 --- a/ansible/reset.yml +++ b/ansible/reset.yml @@ -4,6 +4,6 @@ user: root roles: - stop - - cleanupconfig + - { role: cleanupconfig, when: not reconfig|default(false)|bool } - { role: config, testnet_name: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}" } - start diff --git a/ansible/roles/config/defaults/main.yml b/ansible/roles/config/defaults/main.yml index 994b46660..95060fd44 100644 --- a/ansible/roles/config/defaults/main.yml +++ b/ansible/roles/config/defaults/main.yml @@ -8,5 +8,5 @@ basecoin_group: basecoin basecoin_home: /var/lib/basecoin basecoin_inprocess: false -testnet_name: test-chain - +testnet_name: testnet1 +dev_money: false diff --git a/ansible/roles/config/tasks/basecoin.yml b/ansible/roles/config/tasks/basecoin.yml index 344a89bd7..d47434e06 100644 --- a/ansible/roles/config/tasks/basecoin.yml +++ b/ansible/roles/config/tasks/basecoin.yml @@ -22,11 +22,10 @@ - name: register basecoin public keys as host facts when: basecoin_inprocess|bool - set_fact: "basecoin_pubkey={{basecoinpubkeys.stdout_lines[0]}}" + set_fact: "pubkey={{basecoinpubkeys.stdout_lines[0]}}" connection: local - name: copy basecoin genesis.json - genesis_time will be updated - when: basecoin_inprocess|bool template: src: genesis-basecoin.json.j2 dest: "{{basecoin_home}}/.basecoin/genesis.json" diff --git a/ansible/roles/config/tasks/tendermint.yml b/ansible/roles/config/tasks/tendermint.yml index 90ae9a4c7..046787765 100644 --- a/ansible/roles/config/tasks/tendermint.yml +++ b/ansible/roles/config/tasks/tendermint.yml @@ -19,7 +19,7 @@ changed_when: false - name: register tendermint public keys as host facts - set_fact: "tendermint_pubkey={{tendermintpubkeys.stdout_lines[0]}}" + set_fact: "pubkey={{tendermintpubkeys.stdout_lines[0]}}" connection: local - name: copy tendermint genesis.json - genesis_time will be updated diff --git a/ansible/roles/config/templates/config.toml.j2 b/ansible/roles/config/templates/config.toml.j2 index 4560c9634..6ba8d6d0c 100644 --- a/ansible/roles/config/templates/config.toml.j2 +++ b/ansible/roles/config/templates/config.toml.j2 @@ -8,7 +8,7 @@ db_backend = "leveldb" log_level = "debug" [rpc] -laddr = "tcp://{{ do_private_ip | default('0.0.0.0') }}:46657" +laddr = "tcp://127.0.0.1:46657" [p2p] laddr = "tcp://{{inventory_hostname}}:46656" diff --git a/ansible/roles/config/templates/genesis-basecoin.json.j2 b/ansible/roles/config/templates/genesis-basecoin.json.j2 index f3998a2c6..e1e73b703 100644 --- a/ansible/roles/config/templates/genesis-basecoin.json.j2 +++ b/ansible/roles/config/templates/genesis-basecoin.json.j2 @@ -1,4 +1,23 @@ { + "genesis_time":"{{ansible_date_time.iso8601}}", + "chain_id":"{{testnet_name}}", +{% if basecoin_inprocess|bool %} + "validators": + [ +{% set comma = joiner(",") %} +{% for host in groups[testnet_name] %} + {{ comma() }} + { + "pub_key":{"type":"ed25519","data":{{hostvars[host]["pubkey"]}}}, + "amount":10, + "name":"{{hostvars[host]["ansible_hostname"]}}" + } +{% endfor %} + ], +{% endif %} + "app_hash":"" +{% if dev_money|bool %} + , "app_options": { "accounts": [{ "pub_key": { @@ -12,21 +31,7 @@ } ] }] - }, - "genesis_time":"{{ansible_date_time.iso8601_micro}}", - "chain_id":"{{testnet_name}}", - "validators": - [ -{% set comma = joiner(",") %} -{% for host in groups[testnet_name] %} - {{ comma() }} - { - "pub_key":{"type":"ed25519","data":{{hostvars[host]["basecoin_pubkey"]}}}, - "amount":10, - "name":"{{hostvars[host]["ansible_hostname"]}}" - } -{% endfor %} - ], - "app_hash":"" + } +{% endif %} } diff --git a/ansible/roles/config/templates/genesis-tendermint.json.j2 b/ansible/roles/config/templates/genesis-tendermint.json.j2 index fb4dacbd2..3b68cc6be 100644 --- a/ansible/roles/config/templates/genesis-tendermint.json.j2 +++ b/ansible/roles/config/templates/genesis-tendermint.json.j2 @@ -1,18 +1,4 @@ { - "app_options": { - "accounts": [{ - "pub_key": { - "type": "ed25519", - "data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279" - }, - "coins": [ - { - "denom": "mycoin", - "amount": 9007199254740992 - } - ] - }] - }, "genesis_time":"{{ansible_date_time.iso8601}}", "chain_id":"{{testnet_name}}", "validators": @@ -21,7 +7,7 @@ {% for host in groups[testnet_name] %} {{ comma() }} { - "pub_key":{"type":"ed25519","data":{{hostvars[host]["tendermint_pubkey"]}}}, + "pub_key":{"type":"ed25519","data":{{hostvars[host]["pubkey"]}}}, "amount":10, "name":"{{hostvars[host]["ansible_hostname"]}}" } diff --git a/ansible/roles/install-basecoin/defaults/main.yml b/ansible/roles/install-basecoin/defaults/main.yml index 3fded3836..af0be1460 100644 --- a/ansible/roles/install-basecoin/defaults/main.yml +++ b/ansible/roles/install-basecoin/defaults/main.yml @@ -1,18 +1,12 @@ --- basecoin_release_install: true -basecoin_version: 0.4.0 -basecoin_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/basecoin/v{{basecoin_version}}/basecoin_{{basecoin_version}}_linux_amd64.zip" +basecoin_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/basecoin/v0.4.0/basecoin_0.4.0_linux_amd64.zip" -#If basecoin_release_install == false, copy the binary from here basecoin_binary: "{{ lookup('env','GOPATH') | default('') }}/bin/basecoin" basecoin_user: basecoin basecoin_group: basecoin -# Upstart start/stop conditions can vary by distribution and environment -basecoin_upstart_start_on: start on runlevel [345] -basecoin_upstart_stop_on: stop on runlevel [!345] - basecoin_home: /var/lib/basecoin basecoin_log_file: /var/log/basecoin.log diff --git a/ansible/roles/install-basecoin/tasks/install.yml b/ansible/roles/install-basecoin/tasks/install.yml index 1ac0b39b0..2007fadcf 100644 --- a/ansible/roles/install-basecoin/tasks/install.yml +++ b/ansible/roles/install-basecoin/tasks/install.yml @@ -104,10 +104,10 @@ - reload systemd - name: Create example folder - file: path=/usr/share/basecoin/example-keys state=directory + file: path=/usr/share/basecoin/dev-keys state=directory - name: Copy example keys - copy: "src={{item}} dest=/usr/share/basecoin/example-keys/{{item}}" + copy: "src={{item}} dest=/usr/share/basecoin/dev-keys/{{item}}" with_items: - key.json - key2.json diff --git a/ansible/roles/install-basecoin/templates/basecoin.conf.j2 b/ansible/roles/install-basecoin/templates/basecoin.conf.j2 index 61fcb0f03..ac850da67 100644 --- a/ansible/roles/install-basecoin/templates/basecoin.conf.j2 +++ b/ansible/roles/install-basecoin/templates/basecoin.conf.j2 @@ -1,8 +1,8 @@ # Basecoin (Upstart unit) description "Basecoin" -start on {{ basecoin_upstart_start_on }} -stop on {{ basecoin_upstart_stop_on }} +start on runlevel [2345] +stop on runlevel [!2345] script # Use su to become tendermint user non-interactively on old Upstart versions (see http://superuser.com/a/234541/76168) diff --git a/ansible/roles/install-tendermint/defaults/main.yml b/ansible/roles/install-tendermint/defaults/main.yml index 69fc1b96f..ab1c114f6 100644 --- a/ansible/roles/install-tendermint/defaults/main.yml +++ b/ansible/roles/install-tendermint/defaults/main.yml @@ -1,18 +1,14 @@ --- tendermint_release_install: true -tendermint_version: 0.10.0-rc1 -tendermint_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/tendermint/v{{tendermint_version}}/tendermint_{{tendermint_version}}_linux_amd64.zip" +tendermint_download: "https://s3-us-west-2.amazonaws.com/tendermint/binaries/tendermint/v0.10.0-rc1/tendermint_0.10.0-rc1_linux_amd64.zip" -#If tendermint_release_install == false, copy the binary from here tendermint_binary: "{{ lookup('env','GOPATH') | default('') }}/bin/tendermint" tendermint_user: tendermint tendermint_group: tendermint -# Upstart start/stop conditions can vary by distribution and environment -tendermint_upstart_start_on: start on runlevel [345] -tendermint_upstart_stop_on: stop on runlevel [!345] - tendermint_home: /var/lib/tendermint tendermint_log_file: /var/log/tendermint.log +basecoin_inprocess: false + diff --git a/ansible/roles/install-tendermint/templates/tendermint.conf.j2 b/ansible/roles/install-tendermint/templates/tendermint.conf.j2 index 362094a21..513b16253 100644 --- a/ansible/roles/install-tendermint/templates/tendermint.conf.j2 +++ b/ansible/roles/install-tendermint/templates/tendermint.conf.j2 @@ -1,8 +1,8 @@ # Tendermint (Upstart unit) description "Tendermint" -start on {{ tendermint_upstart_start_on }} -stop on {{ tendermint_upstart_stop_on }} +{{basecoin_inprocess|bool | ternary('','start on (runlevel [2345] and started basecoin)')}} +{{basecoin_inprocess|bool | ternary('','stop on (runlevel [!2345] and stopping basecoin)')}} script # Use su to become tendermint user non-interactively on old Upstart versions (see http://superuser.com/a/234541/76168) diff --git a/ansible/roles/install-tendermint/templates/tendermint.systemd.j2 b/ansible/roles/install-tendermint/templates/tendermint.systemd.j2 index 2e22a563a..20c5d44b0 100644 --- a/ansible/roles/install-tendermint/templates/tendermint.systemd.j2 +++ b/ansible/roles/install-tendermint/templates/tendermint.systemd.j2 @@ -1,6 +1,6 @@ [Unit] Description=Tendermint -Requires=network-online.target +Requires=network-online.target{{basecoin_inprocess|bool | ternary('',' basecoin.target')}} After=network-online.target [Service] diff --git a/ansible/roles/stop/tasks/main.yml b/ansible/roles/stop/tasks/main.yml index 0636018e4..de462a678 100644 --- a/ansible/roles/stop/tasks/main.yml +++ b/ansible/roles/stop/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: stop tendermint - when: not basecoin_inprocess|bool + #when: not basecoin_inprocess|bool service: name=tendermint state=stopped - name: stop basecoin diff --git a/terraform-digitalocean/cluster/main.tf b/terraform-digitalocean/cluster/main.tf index 43166e7de..b9be67c5a 100644 --- a/terraform-digitalocean/cluster/main.tf +++ b/terraform-digitalocean/cluster/main.tf @@ -23,3 +23,9 @@ resource "digitalocean_droplet" "cluster" { } +#resource "digitalocean_floating_ip" "cluster" { +# droplet_id = "${element(digitalocean_droplet.cluster.*.id,count.index)}" +# region = "${element(digitalocean_droplet.cluster.*.region,count.index)}" +# count = "${var.servers}" +#} + diff --git a/terraform-digitalocean/cluster/outputs.tf b/terraform-digitalocean/cluster/outputs.tf index 59ecb9fb9..90255cfcd 100644 --- a/terraform-digitalocean/cluster/outputs.tf +++ b/terraform-digitalocean/cluster/outputs.tf @@ -1,19 +1,25 @@ -// The cluster name, e.g cdn +// The cluster name output "name" { value = "${var.name}" } -// The list of cluster instance ids +// The list of cluster instance IDs output "instances" { value = ["${digitalocean_droplet.cluster.*.id}"] } -// The list of cluster instance ips +// The list of cluster instance private IPs output "private_ips" { value = ["${digitalocean_droplet.cluster.*.ipv4_address_private}"] } -// The list of cluster instance ips +// The list of cluster instance public IPs output "public_ips" { value = ["${digitalocean_droplet.cluster.*.ipv4_address}"] } + +#// The list of cluster floating IPs +#output "floating_ips" { +# value = ["${digitalocean_floating_ip.cluster.*.ip_address}"] +#} + diff --git a/terraform-digitalocean/main.tf b/terraform-digitalocean/main.tf index dec255b1e..bd08af898 100644 --- a/terraform-digitalocean/main.tf +++ b/terraform-digitalocean/main.tf @@ -37,15 +37,7 @@ output "public_ips" { value = "${module.cluster.public_ips}" } -output "private_ips" { - value = "${join(",",module.cluster.private_ips)}" -} - -output "seeds" { - value = "${join(":46656,",module.cluster.public_ips)}:46656" -} - -output "rpcs" { - value = "${join(":46657,",module.cluster.public_ips)}:46657" -} +#output "floating_ips" { +# value = "${module.cluster.floating_ips}" +#}