map.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. .. _salt-cloud-map:
  2. ==============
  3. Cloud Map File
  4. ==============
  5. A number of options exist when creating virtual machines. They can be managed
  6. directly from profiles and the command line execution, or a more complex map
  7. file can be created. The map file allows for a number of virtual machines to
  8. be created and associated with specific profiles. The map file is designed to
  9. be run once to create these more complex scenarios using salt-cloud.
  10. Map files have a simple format, specify a profile and then a list of virtual
  11. machines to make from said profile:
  12. .. code-block:: yaml
  13. fedora_small:
  14. - web1
  15. - web2
  16. - web3
  17. fedora_high:
  18. - redis1
  19. - redis2
  20. - redis3
  21. cent_high:
  22. - riak1
  23. - riak2
  24. - riak3
  25. This map file can then be called to roll out all of these virtual machines. Map
  26. files are called from the salt-cloud command with the -m option:
  27. .. code-block:: bash
  28. $ salt-cloud -m /path/to/mapfile
  29. Remember, that as with direct profile provisioning the -P option can be passed
  30. to create the virtual machines in parallel:
  31. .. code-block:: bash
  32. $ salt-cloud -m /path/to/mapfile -P
  33. .. note::
  34. Due to limitations in the GoGrid API, instances cannot be provisioned in parallel
  35. with the GoGrid driver. Map files will work with GoGrid, but the ``-P``
  36. argument should not be used on maps referencing GoGrid instances.
  37. A map file can also be enforced to represent the total state of a cloud
  38. deployment by using the ``--hard`` option. When using the hard option any vms
  39. that exist but are not specified in the map file will be destroyed:
  40. .. code-block:: bash
  41. $ salt-cloud -m /path/to/mapfile -P -H
  42. Be careful with this argument, it is very dangerous! In fact, it is so
  43. dangerous that in order to use it, you must explicitly enable it in the main
  44. configuration file.
  45. .. code-block:: yaml
  46. enable_hard_maps: True
  47. A map file can include grains and minion configuration options:
  48. .. code-block:: yaml
  49. fedora_small:
  50. - web1:
  51. minion:
  52. log_level: debug
  53. grains:
  54. cheese: tasty
  55. omelet: du fromage
  56. - web2:
  57. minion:
  58. log_level: warn
  59. grains:
  60. cheese: more tasty
  61. omelet: with peppers
  62. Any top level data element from your profile may be overridden in the map file:
  63. .. code-block:: yaml
  64. fedora_small:
  65. - web1:
  66. size: t2.micro
  67. - web2:
  68. size: t2.nano
  69. As of Salt 2017.7.0, nested elements are merged, and can can be specified
  70. individually without having to repeat the complete definition for each top
  71. level data element. In this example a separate MAC is assigned to each VMware
  72. instance while inheriting device parameters for for disk and network
  73. configuration:
  74. .. code-block:: yaml
  75. nyc-vm:
  76. - db1:
  77. devices:
  78. network:
  79. Network Adapter 1:
  80. mac: '44:44:44:44:44:41'
  81. - db2:
  82. devices:
  83. network:
  84. Network Adapter 1:
  85. mac: '44:44:44:44:44:42'
  86. A map file may also be used with the various query options:
  87. .. code-block:: bash
  88. $ salt-cloud -m /path/to/mapfile -Q
  89. {'ec2': {'web1': {'id': 'i-e6aqfegb',
  90. 'image': None,
  91. 'private_ips': [],
  92. 'public_ips': [],
  93. 'size': None,
  94. 'state': 0}},
  95. 'web2': {'Absent'}}
  96. ...or with the delete option:
  97. .. code-block:: bash
  98. $ salt-cloud -m /path/to/mapfile -d
  99. The following virtual machines are set to be destroyed:
  100. web1
  101. web2
  102. Proceed? [N/y]
  103. .. warning:: Specifying Nodes with Maps on the Command Line
  104. Specifying the name of a node or nodes with the maps options on the command
  105. line is *not* supported. This is especially important to remember when
  106. using ``--destroy`` with maps; ``salt-cloud`` will ignore any arguments
  107. passed in which are not directly relevant to the map file. *When using
  108. ``--destroy`` with a map, every node in the map file will be deleted!*
  109. Maps don't provide any useful information for destroying individual nodes,
  110. and should not be used to destroy a subset of a map.
  111. Requiring Other Instances
  112. =========================
  113. The ``requires`` directive can be used in map files to ensure that one instance
  114. is created and available before another is created.
  115. .. code-block:: yaml
  116. fedora_high:
  117. - db1:
  118. size: m5.xlarge
  119. - web1:
  120. size: m5.large
  121. requires:
  122. - db1
  123. This requisite is passed to the instance definition dicitonary in a map file
  124. and accepts a list of instance names as defined in the map.
  125. Setting up New Salt Masters
  126. ===========================
  127. Bootstrapping a new master in the map is as simple as:
  128. .. code-block:: yaml
  129. fedora_small:
  130. - web1:
  131. make_master: True
  132. - web2
  133. - web3
  134. Notice that **ALL** bootstrapped minions from the map will answer to the newly
  135. created salt-master.
  136. To make any of the bootstrapped minions answer to the bootstrapping salt-master
  137. as opposed to the newly created salt-master, as an example:
  138. .. code-block:: yaml
  139. fedora_small:
  140. - web1:
  141. make_master: True
  142. minion:
  143. master: <the local master ip address>
  144. local_master: True
  145. - web2
  146. - web3
  147. The above says the minion running on the newly created salt-master responds to
  148. the local master, ie, the master used to bootstrap these VMs.
  149. Another example:
  150. .. code-block:: yaml
  151. fedora_small:
  152. - web1:
  153. make_master: True
  154. - web2
  155. - web3:
  156. minion:
  157. master: <the local master ip address>
  158. local_master: True
  159. The above example makes the ``web3`` minion answer to the local master, not the
  160. newly created master.
  161. Using Direct Map Data
  162. =====================
  163. When using modules that access the ``CloudClient`` directly (notably, the
  164. ``cloud`` execution and runner modules), it is possible to pass in the contents
  165. of a map file, rather than a path to the location of the map file.
  166. Normally when using these modules, the path to the map file is passed in using:
  167. .. code-block:: bash
  168. salt-run cloud.map_run /path/to/cloud.map
  169. To pass in the actual map data, use the ``map_data`` argument:
  170. .. code-block:: bash
  171. salt-run cloud.map_run map_data='{"centos7": [{"saltmaster": {"minion": \
  172. {"transport": "tcp"}, "make_master": true, "master": {"transport": \
  173. "tcp"}}}, {"minion001": {"minion": {"transport": "tcp"}}}]}'