deploy.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. ========================
  2. Cloud deployment scripts
  3. ========================
  4. Salt Cloud works primarily by executing a script on the virtual machines as
  5. soon as they become available. The script that is executed is referenced in the
  6. cloud profile as the ``script``. In older versions, this was the ``os``
  7. argument. This was changed in 0.8.2.
  8. A number of legacy scripts exist in the deploy directory in the saltcloud
  9. source tree. The preferred method is currently to use the salt-bootstrap
  10. script. A stable version is included with each release tarball starting with
  11. 0.8.4. The most updated version can be found at:
  12. https://github.com/saltstack/salt-bootstrap
  13. Note that, somewhat counter-intuitively, this script is referenced as
  14. ``bootstrap-salt`` in the configuration.
  15. You can specify a deploy script in the cloud configuration file
  16. (``/etc/salt/cloud`` by default):
  17. .. code-block:: yaml
  18. script: bootstrap-salt
  19. Or in a provider:
  20. .. code-block:: yaml
  21. my-provider:
  22. # snip...
  23. script: bootstrap-salt
  24. Or in a profile:
  25. .. code-block:: yaml
  26. my-profile:
  27. provider: my-provider
  28. # snip...
  29. script: bootstrap-salt
  30. If you do not specify a script argument in your cloud configuration file,
  31. provider configuration or profile configuration, the "bootstrap-salt" script
  32. will be used by default.
  33. Other Generic Deploy Scripts
  34. ============================
  35. If you want to be assured of always using the latest Salt Bootstrap script,
  36. there are a few generic templates available in the deploy directory of your
  37. saltcloud source tree:
  38. .. code-block:: bash
  39. curl-bootstrap
  40. curl-bootstrap-git
  41. python-bootstrap
  42. wget-bootstrap
  43. wget-bootstrap-git
  44. These are example scripts which were designed to be customized, adapted, and
  45. refit to meet your needs. One important use of them is to pass options to
  46. the salt-bootstrap script, such as updating to specific git tags.
  47. Custom Deploy Scripts
  48. =====================
  49. If the Salt Bootstrap script does not meet your needs, you may write your own.
  50. The script should be written in shell and is a Jinja template. Deploy scripts
  51. need to execute a number of functions to do a complete salt setup. These
  52. functions include:
  53. 1. Install the salt minion. If this can be done via system packages this method
  54. is HIGHLY preferred.
  55. 2. Add the salt minion keys before the minion is started for the first time.
  56. The minion keys are available as strings that can be copied into place in
  57. the Jinja template under the dict named "vm".
  58. 3. Start the salt-minion daemon and enable it at startup time.
  59. 4. Set up the minion configuration file from the "minion" data available in
  60. the Jinja template.
  61. A good, well commented example of this process is the Fedora deployment
  62. script:
  63. https://github.com/saltstack/salt/blob/develop/salt/cloud/deploy/Fedora.sh
  64. A number of legacy deploy scripts are included with the release tarball. None
  65. of them are as functional or complete as Salt Bootstrap, and are still included
  66. for academic purposes.
  67. Custom deploy scripts are picked up from ``/etc/salt/cloud.deploy.d`` by
  68. default, but you can change the location of deploy scripts with the cloud
  69. configuration ``deploy_scripts_search_path``. Additionally, if your deploy
  70. script has the extension ``.sh``, you can leave out the extension in your
  71. configuration.
  72. For example, if your custom deploy script is located in
  73. ``/etc/salt/cloud.deploy.d/my_deploy.sh``, you could specify it in a cloud
  74. profile like this:
  75. .. code-block:: yaml
  76. my-profile:
  77. provider: my-provider
  78. # snip...
  79. script: my_deploy
  80. You're also free to use the full path to the script if you like. Using full
  81. paths, your script doesn't have to live inside ``/etc/salt/cloud.deploy.d`` or
  82. whatever you've configured with ``deploy_scripts_search_path``.
  83. Post-Deploy Commands
  84. ====================
  85. Once a minion has been deployed, it has the option to run a salt command.
  86. Normally, this would be the :py:func:`state.apply <salt.modules.state.apply_>`,
  87. which would finish provisioning the VM. Another common option (for testing) is
  88. to use :py:func:`test.version <salt.modules.test.version>`. This is configured in the
  89. main cloud config file:
  90. .. code-block:: yaml
  91. start_action: state.apply
  92. This is currently considered to be experimental functionality, and may not work
  93. well with all cloud hosts. If you experience problems with Salt Cloud hanging
  94. after Salt is deployed, consider using Startup States instead:
  95. http://docs.saltstack.com/ref/states/startup.html
  96. Skipping the Deploy Script
  97. ==========================
  98. For whatever reason, you may want to skip the deploy script altogether. This
  99. results in a VM being spun up much faster, with absolutely no configuration.
  100. This can be set from the command line:
  101. .. code-block:: bash
  102. salt-cloud --no-deploy -p micro_aws my_instance
  103. Or it can be set from the main cloud config file:
  104. .. code-block:: yaml
  105. deploy: False
  106. Or it can be set from the provider's configuration:
  107. .. code-block:: yaml
  108. RACKSPACE.user: example_user
  109. RACKSPACE.apikey: 123984bjjas87034
  110. RACKSPACE.deploy: False
  111. Or even on the VM's profile settings:
  112. .. code-block:: yaml
  113. ubuntu_aws:
  114. provider: my-ec2-config
  115. image: ami-7e2da54e
  116. size: t1.micro
  117. deploy: False
  118. The default for deploy is True.
  119. In the profile, you may also set the script option to ``None``:
  120. .. code-block:: yaml
  121. script: None
  122. This is the slowest option, since it still uploads the None deploy script and
  123. executes it.
  124. Updating Salt Bootstrap
  125. =======================
  126. Salt Bootstrap can be updated automatically with ``salt-cloud``:
  127. .. code-block:: bash
  128. salt-cloud -u
  129. salt-cloud --update-bootstrap
  130. Bear in mind that this updates to the latest **stable** version from:
  131. https://bootstrap.saltstack.com/stable/bootstrap-salt.sh
  132. To update Salt Bootstrap script to the **develop** version, run the following
  133. command on the Salt minion host with ``salt-cloud`` installed:
  134. .. code-block:: bash
  135. salt-call config.gather_bootstrap_script 'https://bootstrap.saltstack.com/develop/bootstrap-salt.sh'
  136. Or just download the file manually:
  137. .. code-block:: bash
  138. curl -L 'https://bootstrap.saltstack.com/develop' > /etc/salt/cloud.deploy.d/bootstrap-salt.sh
  139. Keeping /tmp/ Files
  140. ===================
  141. When Salt Cloud deploys an instance, it uploads temporary files to /tmp/ for
  142. salt-bootstrap to put in place. After the script has run, they are deleted. To
  143. keep these files around (mostly for debugging purposes), the --keep-tmp option
  144. can be added:
  145. .. code-block:: bash
  146. salt-cloud -p myprofile mymachine --keep-tmp
  147. For those wondering why /tmp/ was used instead of /root/, this had to be done
  148. for images which require the use of sudo, and therefore do not allow remote
  149. root logins, even for file transfers (which makes /root/ unavailable).
  150. Deploy Script Arguments
  151. =======================
  152. Custom deploy scripts are unlikely to need custom arguments to be passed to
  153. them, but salt-bootstrap has been extended quite a bit, and this may be
  154. necessary. script_args can be specified in either the profile or the map file,
  155. to pass arguments to the deploy script:
  156. .. code-block:: yaml
  157. aws-amazon:
  158. provider: my-ec2-config
  159. image: ami-1624987f
  160. size: t1.micro
  161. ssh_username: ec2-user
  162. script: bootstrap-salt
  163. script_args: -c /tmp/
  164. This has also been tested to work with pipes, if needed:
  165. .. code-block:: yaml
  166. script_args: '| head'