map.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. Setting up New Salt Masters
  112. ===========================
  113. Bootstrapping a new master in the map is as simple as:
  114. .. code-block:: yaml
  115. fedora_small:
  116. - web1:
  117. make_master: True
  118. - web2
  119. - web3
  120. Notice that **ALL** bootstrapped minions from the map will answer to the newly
  121. created salt-master.
  122. To make any of the bootstrapped minions answer to the bootstrapping salt-master
  123. as opposed to the newly created salt-master, as an example:
  124. .. code-block:: yaml
  125. fedora_small:
  126. - web1:
  127. make_master: True
  128. minion:
  129. master: <the local master ip address>
  130. local_master: True
  131. - web2
  132. - web3
  133. The above says the minion running on the newly created salt-master responds to
  134. the local master, ie, the master used to bootstrap these VMs.
  135. Another example:
  136. .. code-block:: yaml
  137. fedora_small:
  138. - web1:
  139. make_master: True
  140. - web2
  141. - web3:
  142. minion:
  143. master: <the local master ip address>
  144. local_master: True
  145. The above example makes the ``web3`` minion answer to the local master, not the
  146. newly created master.
  147. Using Direct Map Data
  148. =====================
  149. When using modules that access the ``CloudClient`` directly (notably, the
  150. ``cloud`` execution and runner modules), it is possible to pass in the contents
  151. of a map file, rather than a path to the location of the map file.
  152. Normally when using these modules, the path to the map file is passed in using:
  153. .. code-block:: bash
  154. salt-run cloud.map_run /path/to/cloud.map
  155. To pass in the actual map data, use the ``map_data`` argument:
  156. .. code-block:: bash
  157. salt-run cloud.map_run map_data='{"centos7": [{"saltmaster": {"minion": \
  158. {"transport": "tcp"}, "make_master": true, "master": {"transport": \
  159. "tcp"}}}, {"minion001": {"minion": {"transport": "tcp"}}}]}'