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.

202 lines
8.5 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. If you have (Homebrew)[https://brew.sh] installed, then it's simply
  33. ```
  34. brew install ansible
  35. ```
  36. If not, you can install it using `pip`:
  37. ```
  38. sudo easy_install pip
  39. sudo pip install ansible
  40. ```
  41. 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.
  42. ```
  43. ssh-agent > ~/.ssh/ssh.env
  44. source ~/.ssh/ssh.env
  45. ssh-add private.key
  46. ```
  47. Subsequently, as long as the agent is running, you can use `source ~/.ssh/ssh.env` to load the keys to the current session.
  48. Note: On Mac OSX, you can add the `-K` option to ssh-add to store the passphrase in your keychain. The security of this feature is debated but it is convenient.
  49. ### Optional cloud dependencies
  50. If you are using a cloud provider to host your servers, you need the below dependencies installed on your local machine.
  51. #### DigitalOcean inventory dependencies:
  52. Ubuntu/Debian:
  53. ```
  54. sudo apt-get install python-pip
  55. sudo pip install dopy
  56. ```
  57. CentOS/RedHat:
  58. ```
  59. sudo yum install python-pip
  60. sudo pip install dopy
  61. ```
  62. Mac OSX:
  63. ```
  64. sudo pip install dopy
  65. ```
  66. #### Amazon AWS inventory dependencies:
  67. Ubuntu/Debian:
  68. ```
  69. sudo apt-get install python-boto
  70. ```
  71. CentOS/RedHat:
  72. ```
  73. sudo yum install python-boto
  74. ```
  75. Mac OSX:
  76. ```
  77. sudo pip install boto
  78. ```
  79. ## Refreshing the DigitalOcean inventory
  80. If you just finished creating droplets, the local DigitalOcean inventory cache is not up-to-date. To refresh it, run:
  81. ```
  82. DO_API_TOKEN="<The API token received from DigitalOcean>"
  83. python -u inventory/digital_ocean.py --refresh-cache 1> /dev/null
  84. ```
  85. ## Refreshing the Amazon AWS inventory
  86. If you just finished creating Amazon AWS EC2 instances, the local AWS inventory cache is not up-to-date. To refresh it, run:
  87. ```
  88. AWS_ACCESS_KEY_ID='<The API access key ID received from Amazon>'
  89. AWS_SECRET_ACCESS_KEY='<The API secret access key received from Amazon>'
  90. python -u inventory/ec2.py --refresh-cache 1> /dev/null
  91. ```
  92. 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.
  93. ## Running the playbooks
  94. 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.
  95. 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.
  96. 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.
  97. 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.
  98. 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.
  99. ### DigitalOcean
  100. ```
  101. DO_API_TOKEN="<The API token received from DigitalOcean>"
  102. TF_VAR_TESTNET_NAME="testnet-servers"
  103. ansible-playbook -i inventory/digital_ocean.py install.yml -e service=basecoin
  104. ```
  105. ### Amazon AWS
  106. ```
  107. AWS_ACCESS_KEY_ID='<The API access key ID received from Amazon>'
  108. AWS_SECRET_ACCESS_KEY='<The API secret access key received from Amazon>'
  109. TF_VAR_TESTNET_NAME="testnet-servers"
  110. ansible-playbook -i inventory/ec2.py install.yml -e service=basecoin
  111. ```
  112. ### Installing custom versions
  113. 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.
  114. ```
  115. GOPATH="<your go path>"
  116. go get -u github.com/tendermint/basecoin/cmd/basecoin
  117. DO_API_TOKEN="<The API token received from DigitalOcean>"
  118. TF_VAR_TESTNET_NAME="testnet-servers"
  119. ansible-playbook -i inventory/digital_ocean.py install.yml -e service=basecoin -e release_install=false
  120. ```
  121. Alternatively you can change the variable settings in `group_vars/all`.
  122. ## Other commands and roles
  123. There are few extra playbooks to make life easier managing your servers.
  124. * install.yml - Install basecoin or ethermint applications. (Tendermint gets installed automatically.) Use the `service` parameter to define which application to install. Defaults to `basecoin`.
  125. * 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.
  126. * 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.
  127. * stop.yml - Stop the application. You need to pass `-e service=<servicename>`.
  128. * status.yml - Check the service status and print it. You need to pass `-e service=<servicename>`.
  129. * start.yml - Start the application. You need to pass `-e service=<servicename>`.
  130. * ubuntu16-patch.yml - Ubuntu 16.04 does not have the minimum required python package installed to be able to run ansible. If you are using ubuntu, run this playbook first on the target machines. This will install the python pacakge that is required for ansible to work correctly on the remote nodes.
  131. * upgrade.yml - Upgrade the `service` on your testnet. It will stop the service and restart it at the end. It will only work if the upgraded version is backward compatible with the installed version.
  132. * upgrade-reset.yml - Upgrade the `service` on your testnet and reset the database. It will stop the service and restart it at the end. It will work for upgrades where the new version is not backward-compatible with the installed version - however it will reset the testnet to its default.
  133. The roles are self-sufficient under the `roles/` folder.
  134. * install - install the application defined in the `service` parameter. It can install release packages and update them with custom-compiled binaries.
  135. * unsafe_reset - delete the database for a service, including the tendermint database.
  136. * config - configure the application defined in `service`. It also configures the underlying tendermint service. Check `group_vars/all` for options.
  137. * stop - stop an application. Requires the `service` parameter set.
  138. * status - check the status of an application. Requires the `service` parameter set.
  139. * start - start an application. Requires the `service` parameter set.
  140. ## Default variables
  141. 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.