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.

288 lines
9.0 KiB

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