You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
7.4 KiB

  1. # Ansible playbook for Tendermint applications
  2. ![Ansible plus Tendermint](img/a_plus_t.png)
  3. * [Prerequisites](#Prerequisites)
  4. * [Ansible setup](#Ansible setup)
  5. * [Running the playbook](#Running the playbook)
  6. The playbooks in this folder run [ansible](http://www.ansible.com/) roles which:
  7. * install and configure basecoin or ethermint
  8. * start/stop basecoin or ethermint and reset their configuration
  9. ## Prerequisites
  10. * Ansible 2.0 or higher
  11. * SSH key to the servers
  12. Optional for DigitalOcean droplets:
  13. * DigitalOcean API Token
  14. * python dopy package
  15. Head over to the [Terraform folder](https://github.com/tendermint/tools/tree/master/terraform-digitalocean) for a description on how to get a DigitalOcean API Token.
  16. Optional for Amazon AWS instances:
  17. * Amazon AWS API access key ID and secret access key.
  18. 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.
  19. ## Ansible setup
  20. Ansible requires a "command machine" or "local machine" or "orchestrator machine" to run on. This can be your laptop or any machine that can run ansible. (It does not have to be part of the cloud network that hosts your servers.)
  21. Use the official [Ansible installation guide](http://docs.ansible.com/ansible/intro_installation.html) to install Ansible. Here are a few examples on basic installation commands:
  22. Ubuntu/Debian:
  23. ```
  24. sudo apt-get install ansible
  25. ```
  26. CentOS/RedHat:
  27. ```
  28. sudo yum install epel-release
  29. sudo yum install ansible
  30. ```
  31. Mac OSX:
  32. ```
  33. sudo easy_install pip
  34. sudo pip install ansible
  35. ```
  36. 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.
  37. ```
  38. ssh-agent > ~/.ssh/ssh.env
  39. source ~/.ssh/ssh.env
  40. ssh-add private.key
  41. ```
  42. Subsequently, as long as the agent is running, you can use `source ~/.ssh/ssh.env` to load the keys to the current session.
  43. ### Optional cloud dependencies
  44. If you are using a cloud provider to host your servers, you need the below dependencies installed on your local machine.
  45. #### DigitalOcean inventory dependencies:
  46. Ubuntu/Debian:
  47. ```
  48. sudo apt-get install python-pip
  49. sudo pip install dopy
  50. ```
  51. CentOS/RedHat:
  52. ```
  53. sudo yum install python-pip
  54. sudo pip install dopy
  55. ```
  56. Mac OSX:
  57. ```
  58. sudo pip install dopy
  59. ```
  60. #### Amazon AWS inventory dependencies:
  61. Ubuntu/Debian:
  62. ```
  63. sudo apt-get install python-boto
  64. ```
  65. CentOS/RedHat:
  66. ```
  67. sudo yum install python-boto
  68. ```
  69. Mac OSX:
  70. ```
  71. sudo pip install boto
  72. ```
  73. ## Refreshing the DigitalOcean inventory
  74. If you just finished creating droplets, the local DigitalOcean inventory cache is not up-to-date. To refresh it, run:
  75. ```
  76. DO_API_TOKEN="<The API token received from DigitalOcean>"
  77. python -u inventory/digital_ocean.py --refresh-cache 1> /dev/null
  78. ```
  79. ## Refreshing the Amazon AWS inventory
  80. If you just finished creating Amazon AWS EC2 instances, the local AWS inventory cache is not up-to-date. To refresh it, run:
  81. ```
  82. AWS_ACCESS_KEY_ID='<The API access key ID received from Amazon>'
  83. AWS_SECRET_ACCESS_KEY='<The API secret access key received from Amazon>'
  84. python -u inventory/ec2.py --refresh-cache 1> /dev/null
  85. ```
  86. 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.
  87. ## Running the playbooks
  88. The playbooks are locked down to only run if the environment variable `TF_VAR_TESTNET_NAME` is populated. This is a precaution so you don't accidentally run the playbook on all your servers.
  89. The variable `TF_VAR_TESTNET_NAME` contains the testnet name which ansible translates into an ansible group. If you used Terraform to create the servers, it was the testnet name used there.
  90. If the playbook cannot connect to the servers because of public key denial, your SSH Agent is not set up properly. Alternatively you can add the SSH key to ansible using the `--private-key` option.
  91. If you need to connect to the nodes as root but your local username is different, use the ansible option `-u root` to tell ansible to connect to the servers and authenticate as the root user.
  92. If you secured your server and you need to `sudo` for root access, use the the `-b` or `--become` option to tell ansible to sudo to root after connecting to the server. In the Terraform-DigitalOcean example, if you created the ec2-user by adding the `noroot=true` option (or if you are simply on Amazon AWS), you need to add the options `-u ec2-user -b` to ansible to tell it to connect as the ec2-user and then sudo to root to run the playbook.
  93. ### DigitalOcean
  94. ```
  95. DO_API_TOKEN="<The API token received from DigitalOcean>"
  96. TF_VAR_TESTNET_NAME="testnet-servers"
  97. ansible-playbook -i inventory/digital_ocean.py install.yml -e service=basecoin
  98. ```
  99. ### Amazon AWS
  100. ```
  101. AWS_ACCESS_KEY_ID='<The API access key ID received from Amazon>'
  102. AWS_SECRET_ACCESS_KEY='<The API secret access key received from Amazon>'
  103. TF_VAR_TESTNET_NAME="testnet-servers"
  104. ansible-playbook -i inventory/ec2.py install.yml -e service=basecoin
  105. ```
  106. ### Installing custom versions
  107. By default ansible installs the tendermint, basecoin or ethermint binary versions from the latest release in the repository. If you build your own version of the binaries, you can tell ansible to install that instead.
  108. ```
  109. GOPATH="<your go path>"
  110. go get -u github.com/tendermint/basecoin/cmd/basecoin
  111. DO_API_TOKEN="<The API token received from DigitalOcean>"
  112. TF_VAR_TESTNET_NAME="testnet-servers"
  113. ansible-playbook -i inventory/digital_ocean.py install.yml -e service=basecoin -e release_install=false
  114. ```
  115. Alternatively you can change the variable settings in `group_vars/all`.
  116. ## Other commands and roles
  117. There are few extra playbooks to make life easier managing your servers.
  118. * install.yml - Install basecoin or ethermint applications. (Tendermint gets installed automatically.) Use the `service` parameter to define which application to install. Defaults to `basecoin`.
  119. * reset.yml - Stop the application, reset the configuration and data, then start the application again. You need to pass `-e service=<servicename>`, like `-e service=basecoin`. It will restart the underlying tendermint application too.
  120. * restart.yml - Restart a service on all nodes. You need to pass `-e service=<servicename>`, like `-e service=basecoin`. It will restart the underlying tendermint application too.
  121. * stop.yml - Stop the application. You need to pass `-e service=<servicename>`.
  122. * start.yml - Start the application. You need to pass `-e service=<servicename>`.
  123. The roles are self-sufficient under the `roles/` folder.
  124. * install-tendermint - install the tendermint application. It can install release packages or custom-compiled binaries.
  125. * install - install the application defined in the `service` parameter. It can install release packages and update them with custom-compiled binaries.
  126. * rmdb - delete the tendermint database for a service.
  127. * config - configure the application defined in `service`. It also configures the underlying tendermint service. Check `group_vars/all` for options.
  128. * stop - stop an application. Requires the `service` parameter set.
  129. * start - start an application. Requires the `service` parameter set.
  130. ## Default variables
  131. Default variables are documented under `group_vars/all`. You can the parameters there to deploy a previously created genesis.json file (instead of dynamically creating it) or if you want to deploy custom built binaries instead of deploying a released version.