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.

294 lines
9.1 KiB

  1. Ansible playbook for Tendermint applications
  2. ============================================
  3. .. figure:: img/a_plus_t.png
  4. :alt: Ansible plus Tendermint
  5. Ansible plus Tendermint
  6. - `Prerequisites <#Prerequisites>`__
  7. - `Ansible setup <#Ansible%20setup>`__
  8. - `Running the playbook <#Running%20the%20playbook>`__
  9. The playbooks in this folder run `ansible <http://www.ansible.com/>`__
  10. roles which:
  11. - install and configure basecoin or ethermint
  12. - start/stop basecoin or ethermint and reset their configuration
  13. Prerequisites
  14. -------------
  15. - Ansible 2.0 or higher
  16. - SSH key to the servers
  17. Optional for DigitalOcean droplets: \* DigitalOcean API Token \* python
  18. dopy package
  19. Head over to the `Terraform
  20. folder <https://github.com/tendermint/tools/tree/master/terraform-digitalocean>`__
  21. for a description on how to get a DigitalOcean API Token.
  22. Optional for Amazon AWS instances: \* Amazon AWS API access key ID and
  23. secret access key.
  24. The cloud inventory scripts come from the ansible team at their
  25. `GitHub <https://github.com/ansible/ansible>`__ page. You can get the
  26. latest version from the contrib/inventory folder.
  27. Ansible setup
  28. -------------
  29. Ansible requires a "command machine" or "local machine" or "orchestrator
  30. machine" to run on. This can be your laptop or any machine that can run
  31. ansible. (It does not have to be part of the cloud network that hosts
  32. your servers.)
  33. Use the official `Ansible installation
  34. guide <http://docs.ansible.com/ansible/intro_installation.html>`__ to
  35. install Ansible. Here are a few examples on basic installation commands:
  36. Ubuntu/Debian:
  37. ::
  38. sudo apt-get install ansible
  39. CentOS/RedHat:
  40. ::
  41. sudo yum install epel-release
  42. sudo yum install ansible
  43. Mac OSX: If you have (Homebrew)[https://brew.sh] installed, then it's
  44. simply
  45. ::
  46. brew install ansible
  47. If not, you can install it using ``pip``:
  48. ::
  49. sudo easy_install pip
  50. sudo pip install ansible
  51. To make life easier, you can start an SSH Agent and load your SSH
  52. key(s). This way ansible will have an uninterrupted way of connecting to
  53. your servers.
  54. ::
  55. ssh-agent > ~/.ssh/ssh.env
  56. source ~/.ssh/ssh.env
  57. ssh-add private.key
  58. Subsequently, as long as the agent is running, you can use
  59. ``source ~/.ssh/ssh.env`` to load the keys to the current session. Note:
  60. On Mac OSX, you can add the ``-K`` option to ssh-add to store the
  61. passphrase in your keychain. The security of this feature is debated but
  62. it is convenient.
  63. Optional cloud dependencies
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. If you are using a cloud provider to host your servers, you need the
  66. below dependencies installed on your local machine.
  67. DigitalOcean inventory dependencies:
  68. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  69. Ubuntu/Debian:
  70. ::
  71. sudo apt-get install python-pip
  72. sudo pip install dopy
  73. CentOS/RedHat:
  74. ::
  75. sudo yum install python-pip
  76. sudo pip install dopy
  77. Mac OSX:
  78. ::
  79. sudo pip install dopy
  80. Amazon AWS inventory dependencies:
  81. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  82. Ubuntu/Debian:
  83. ::
  84. sudo apt-get install python-boto
  85. CentOS/RedHat:
  86. ::
  87. sudo yum install python-boto
  88. Mac OSX:
  89. ::
  90. sudo pip install boto
  91. Refreshing the DigitalOcean inventory
  92. -------------------------------------
  93. If you just finished creating droplets, the local DigitalOcean inventory
  94. cache is not up-to-date. To refresh it, run:
  95. ::
  96. DO_API_TOKEN="<The API token received from DigitalOcean>"
  97. python -u inventory/digital_ocean.py --refresh-cache 1> /dev/null
  98. Refreshing the Amazon AWS inventory
  99. -----------------------------------
  100. If you just finished creating Amazon AWS EC2 instances, the local AWS
  101. inventory cache is not up-to-date. To refresh it, run:
  102. ::
  103. AWS_ACCESS_KEY_ID='<The API access key ID received from Amazon>'
  104. AWS_SECRET_ACCESS_KEY='<The API secret access key received from Amazon>'
  105. python -u inventory/ec2.py --refresh-cache 1> /dev/null
  106. Note: you don't need the access key and secret key set, if you are
  107. running ansible on an Amazon AMI instance with the proper IAM
  108. permissions set.
  109. Running the playbooks
  110. ---------------------
  111. The playbooks are locked down to only run if the environment variable
  112. ``TF_VAR_TESTNET_NAME`` is populated. This is a precaution so you don't
  113. accidentally run the playbook on all your servers.
  114. The variable ``TF_VAR_TESTNET_NAME`` contains the testnet name which
  115. ansible translates into an ansible group. If you used Terraform to
  116. create the servers, it was the testnet name used there.
  117. If the playbook cannot connect to the servers because of public key
  118. denial, your SSH Agent is not set up properly. Alternatively you can add
  119. the SSH key to ansible using the ``--private-key`` option.
  120. If you need to connect to the nodes as root but your local username is
  121. different, use the ansible option ``-u root`` to tell ansible to connect
  122. to the servers and authenticate as the root user.
  123. If you secured your server and you need to ``sudo`` for root access, use
  124. the the ``-b`` or ``--become`` option to tell ansible to sudo to root
  125. after connecting to the server. In the Terraform-DigitalOcean example,
  126. if you created the ec2-user by adding the ``noroot=true`` option (or if
  127. you are simply on Amazon AWS), you need to add the options
  128. ``-u ec2-user -b`` to ansible to tell it to connect as the ec2-user and
  129. then sudo to root to run the playbook.
  130. DigitalOcean
  131. ~~~~~~~~~~~~
  132. ::
  133. DO_API_TOKEN="<The API token received from DigitalOcean>"
  134. TF_VAR_TESTNET_NAME="testnet-servers"
  135. ansible-playbook -i inventory/digital_ocean.py install.yml -e service=basecoin
  136. Amazon AWS
  137. ~~~~~~~~~~
  138. ::
  139. AWS_ACCESS_KEY_ID='<The API access key ID received from Amazon>'
  140. AWS_SECRET_ACCESS_KEY='<The API secret access key received from Amazon>'
  141. TF_VAR_TESTNET_NAME="testnet-servers"
  142. ansible-playbook -i inventory/ec2.py install.yml -e service=basecoin
  143. Installing custom versions
  144. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. By default ansible installs the tendermint, basecoin or ethermint binary
  146. versions from the latest release in the repository. If you build your
  147. own version of the binaries, you can tell ansible to install that
  148. instead.
  149. ::
  150. GOPATH="<your go path>"
  151. go get -u github.com/tendermint/basecoin/cmd/basecoin
  152. DO_API_TOKEN="<The API token received from DigitalOcean>"
  153. TF_VAR_TESTNET_NAME="testnet-servers"
  154. ansible-playbook -i inventory/digital_ocean.py install.yml -e service=basecoin -e release_install=false
  155. Alternatively you can change the variable settings in
  156. ``group_vars/all``.
  157. Other commands and roles
  158. ------------------------
  159. There are few extra playbooks to make life easier managing your servers.
  160. - install.yml - Install basecoin or ethermint applications. (Tendermint
  161. gets installed automatically.) Use the ``service`` parameter to
  162. define which application to install. Defaults to ``basecoin``.
  163. - reset.yml - Stop the application, reset the configuration and data,
  164. then start the application again. You need to pass
  165. ``-e service=<servicename>``, like ``-e service=basecoin``. It will
  166. restart the underlying tendermint application too.
  167. - restart.yml - Restart a service on all nodes. You need to pass
  168. ``-e service=<servicename>``, like ``-e service=basecoin``. It will
  169. restart the underlying tendermint application too.
  170. - stop.yml - Stop the application. You need to pass
  171. ``-e service=<servicename>``.
  172. - status.yml - Check the service status and print it. You need to pass
  173. ``-e service=<servicename>``.
  174. - start.yml - Start the application. You need to pass
  175. ``-e service=<servicename>``.
  176. - ubuntu16-patch.yml - Ubuntu 16.04 does not have the minimum required
  177. python package installed to be able to run ansible. If you are using
  178. ubuntu, run this playbook first on the target machines. This will
  179. install the python pacakge that is required for ansible to work
  180. correctly on the remote nodes.
  181. - upgrade.yml - Upgrade the ``service`` on your testnet. It will stop
  182. the service and restart it at the end. It will only work if the
  183. upgraded version is backward compatible with the installed version.
  184. - upgrade-reset.yml - Upgrade the ``service`` on your testnet and reset
  185. the database. It will stop the service and restart it at the end. It
  186. will work for upgrades where the new version is not
  187. backward-compatible with the installed version - however it will
  188. reset the testnet to its default.
  189. The roles are self-sufficient under the ``roles/`` folder.
  190. - install - install the application defined in the ``service``
  191. parameter. It can install release packages and update them with
  192. custom-compiled binaries.
  193. - unsafe\_reset - delete the database for a service, including the
  194. tendermint database.
  195. - config - configure the application defined in ``service``. It also
  196. configures the underlying tendermint service. Check
  197. ``group_vars/all`` for options.
  198. - stop - stop an application. Requires the ``service`` parameter set.
  199. - status - check the status of an application. Requires the ``service``
  200. parameter set.
  201. - start - start an application. Requires the ``service`` parameter set.
  202. Default variables
  203. -----------------
  204. Default variables are documented under ``group_vars/all``. You can the
  205. parameters there to deploy a previously created genesis.json file
  206. (instead of dynamically creating it) or if you want to deploy custom
  207. built binaries instead of deploying a released version.