esxi_proxy_minion.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. .. _tutorial-esxi-proxy:
  2. =================
  3. ESXi Proxy Minion
  4. =================
  5. .. versionadded:: 2015.8.4
  6. .. note::
  7. This tutorial assumes basic knowledge of Salt. To get up to speed, check
  8. out the :ref:`Salt Walkthrough <tutorial-salt-walk-through>`.
  9. This tutorial also assumes a basic understanding of Salt Proxy Minions. If
  10. you're unfamiliar with Salt's Proxy Minion system, please read the
  11. :ref:`Salt Proxy Minion <proxy-minion>` documentation and the
  12. :ref:`Salt Proxy Minion End-to-End Example <proxy-minion-end-to-end-example>`
  13. tutorial.
  14. The third assumption that this tutorial makes is that you also have a
  15. basic understanding of ESXi hosts. You can learn more about ESXi hosts on
  16. `VMware's various resources`_.
  17. .. _VMware's various resources: https://www.vmware.com/products/esxi-and-esx.html
  18. Salt's ESXi Proxy Minion allows a VMware ESXi host to be treated as an individual
  19. Salt Minion, without installing a Salt Minion on the ESXi host.
  20. Since an ESXi host may not necessarily run on an OS capable of hosting a Python
  21. stack, the ESXi host can't run a regular Salt Minion directly. Therefore, Salt's
  22. Proxy Minion functionality enables you to designate another machine to host a
  23. proxy process that "proxies" communication from the Salt Master to the ESXi host.
  24. The master does not know or care that the ESXi target is not a "real" Salt Minion.
  25. More in-depth conceptual reading on Proxy Minions can be found in the
  26. :ref:`Proxy Minion <proxy-minion>` section of Salt's documentation.
  27. Salt's ESXi Proxy Minion was added in the 2015.8.4 release of Salt.
  28. .. note::
  29. Be aware that some functionality for the ESXi Proxy Minion may depend on the
  30. type of license attached the ESXi host(s).
  31. For example, certain services are only available to manipulate service state
  32. or policies with a VMware vSphere Enterprise or Enterprise Plus license, while
  33. others are available with a Standard license. The ``ntpd`` service is restricted
  34. to an Enterprise Plus license, while ``ssh`` is available via the Standard
  35. license.
  36. Please see the `vSphere Comparison`_ page for more information.
  37. .. _vSphere Comparison: https://www.vmware.com/products/vsphere.html#compare
  38. Dependencies
  39. ============
  40. Manipulation of the ESXi host via a Proxy Minion requires the machine running
  41. the Proxy Minion process to have the ESXCLI package (and all of its dependencies)
  42. and the pyVmomi Python Library to be installed.
  43. ESXi Password
  44. -------------
  45. The ESXi Proxy Minion uses VMware's API to perform tasks on the host as if it was
  46. a regular Salt Minion. In order to access the API that is already running on the
  47. ESXi host, the ESXi host must have a username and password that is used to log
  48. into the host. The username is usually ``root``. Before Salt can access the ESXi
  49. host via VMware's API, a default password *must* be set on the host.
  50. pyVmomi
  51. -------
  52. The pyVmomi Python library must be installed on the machine that is running the
  53. proxy process. pyVmomi can be installed via pip:
  54. .. code-block:: bash
  55. pip install pyVmomi
  56. .. note::
  57. Version 6.0 of pyVmomi has some problems with SSL error handling on certain
  58. versions of Python. If using version 6.0 of pyVmomi, the machine that you
  59. are running the proxy minion process from must have either Python 2.6,
  60. Python 2.7.9, or newer. This is due to an upstream dependency in pyVmomi 6.0
  61. that is not supported in Python version 2.7 to 2.7.8. If the
  62. version of Python running the proxy process is not in the supported range, you
  63. will need to install an earlier version of pyVmomi. See `Issue #29537`_ for
  64. more information.
  65. .. _Issue #29537: https://github.com/saltstack/salt/issues/29537
  66. Based on the note above, to install an earlier version of pyVmomi than the
  67. version currently listed in PyPi, run the following:
  68. .. code-block:: bash
  69. pip install pyVmomi==5.5.0.2014.1.1
  70. The 5.5.0.2014.1.1 is a known stable version that the original ESXi Proxy Minion
  71. was developed against.
  72. ESXCLI
  73. ------
  74. Currently, about a third of the functions used for the ESXi Proxy Minion require
  75. the ESXCLI package be installed on the machine running the Proxy Minion process.
  76. The ESXCLI package is also referred to as the VMware vSphere CLI, or vCLI. VMware
  77. provides vCLI package installation instructions for `vSphere 5.5`_ and
  78. `vSphere 6.0`_.
  79. .. _vSphere 5.5: http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html
  80. .. _vSphere 6.0: http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html
  81. Once all of the required dependencies are in place and the vCLI package is
  82. installed, you can check to see if you can connect to your ESXi host by running
  83. the following command:
  84. .. code-block:: bash
  85. esxcli -s <host-location> -u <username> -p <password> system syslog config get
  86. If the connection was successful, ESXCLI was successfully installed on your system.
  87. You should see output related to the ESXi host's syslog configuration.
  88. Configuration
  89. =============
  90. There are several places where various configuration values need to be set in
  91. order for the ESXi Proxy Minion to run and connect properly.
  92. Proxy Config File
  93. -----------------
  94. On the machine that will be running the Proxy Minon process(es), a proxy config
  95. file must be in place. This file should be located in the ``/etc/salt/`` directory
  96. and should be named ``proxy``. If the file is not there by default, create it.
  97. This file should contain the location of your Salt Master that the Salt Proxy
  98. will connect to.
  99. Example Proxy Config File:
  100. .. code-block:: yaml
  101. # /etc/salt/proxy
  102. master: <salt-master-location>
  103. Pillar Profiles
  104. ---------------
  105. Proxy minions get their configuration from Salt's Pillar. Every proxy must
  106. have a stanza in Pillar and a reference in the Pillar top-file that matches
  107. the Proxy ID. At a minimum for communication with the ESXi host, the pillar
  108. should look like this:
  109. .. code-block:: yaml
  110. proxy:
  111. proxytype: esxi
  112. host: <ip or dns name of esxi host>
  113. username: <ESXi username>
  114. passwords:
  115. - first_password
  116. - second_password
  117. - third_password
  118. Some other optional settings are ``protocol`` and ``port``. These can be added
  119. to the pillar configuration.
  120. proxytype
  121. ^^^^^^^^^
  122. The ``proxytype`` key and value pair is critical, as it tells Salt which
  123. interface to load from the ``proxy`` directory in Salt's install hierarchy,
  124. or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
  125. own proxy module, for example). To use this ESXi Proxy Module, set this to
  126. ``esxi``.
  127. host
  128. ^^^^
  129. The location, or ip/dns, of the ESXi host. Required.
  130. username
  131. ^^^^^^^^
  132. The username used to login to the ESXi host, such as ``root``. Required.
  133. passwords
  134. ^^^^^^^^^
  135. A list of passwords to be used to try and login to the ESXi host. At least
  136. one password in this list is required.
  137. The proxy integration will try the passwords listed in order. It is
  138. configured this way so you can have a regular password and the password you
  139. may be updating for an ESXi host either via the
  140. :mod:`vsphere.update_host_password <salt.modules.vsphere.update_host_password>`
  141. execution module function or via the
  142. :mod:`esxi.password_present <salt.states.esxi.password_present>` state
  143. function. This way, after the password is changed, you should not need to
  144. restart the proxy minion--it should just pick up the new password
  145. provided in the list. You can then change pillar at will to move that
  146. password to the front and retire the unused ones.
  147. Use-case/reasoning for using a list of passwords: You are setting up an
  148. ESXi host for the first time, and the host comes with a default password.
  149. You know that you'll be changing this password during your initial setup
  150. from the default to a new password. If you only have one password option,
  151. and if you have a state changing the password, any remote execution commands
  152. or states that run after the password change will not be able to run on the
  153. host until the password is updated in Pillar and the Proxy Minion process is
  154. restarted.
  155. This allows you to use any number of potential fallback passwords.
  156. .. note::
  157. When a password is changed on the host to one in the list of possible
  158. passwords, the further down on the list the password is, the longer
  159. individual commands will take to return. This is due to the nature of
  160. pyVmomi's login system. We have to wait for the first attempt to fail
  161. before trying the next password on the list.
  162. This scenario is especially true, and even slower, when the proxy
  163. minion first starts. If the correct password is not the first password
  164. on the list, it may take up to a minute for ``test.version`` to respond
  165. with salt's version installed (Example: ``2018.3.4``. Once the initial
  166. authorization is complete, the responses for commands will be a little
  167. faster.
  168. To avoid these longer waiting periods, SaltStack recommends moving the
  169. correct password to the top of the list and restarting the proxy minion
  170. at your earliest convenience.
  171. protocol
  172. ^^^^^^^^
  173. If the ESXi host is not using the default protocol, set this value to an
  174. alternate protocol. Default is ``https``. For example:
  175. port
  176. ^^^^
  177. If the ESXi host is not using the default port, set this value to an
  178. alternate port. Default is ``443``.
  179. Example Configuration Files
  180. ---------------------------
  181. An example of all of the basic configurations that need to be in place before
  182. starting the Proxy Minion processes includes the Proxy Config File, Pillar
  183. Top File, and any individual Proxy Minion Pillar files.
  184. In this example, we'll assuming there are two ESXi hosts to connect to. Therefore,
  185. we'll be creating two Proxy Minion config files, one config for each ESXi host.
  186. Proxy Config File:
  187. .. code-block:: yaml
  188. # /etc/salt/proxy
  189. master: <salt-master-location>
  190. Pillar Top File:
  191. .. code-block:: yaml
  192. # /srv/pillar/top.sls
  193. base:
  194. 'esxi-1':
  195. - esxi-1
  196. 'esxi-2':
  197. - esxi-2
  198. Pillar Config File for the first ESXi host, esxi-1:
  199. .. code-block:: yaml
  200. # /srv/pillar/esxi-1.sls
  201. proxy:
  202. proxytype: esxi
  203. host: esxi-1.example.com
  204. username: 'root'
  205. passwords:
  206. - bad-password-1
  207. - backup-bad-password-1
  208. Pillar Config File for the second ESXi host, esxi-2:
  209. .. code-block:: yaml
  210. # /srv/pillar/esxi-2.sls
  211. proxy:
  212. proxytype: esxi
  213. host: esxi-2.example.com
  214. username: 'root'
  215. passwords:
  216. - bad-password-2
  217. - backup-bad-password-2
  218. Starting the Proxy Minion
  219. =========================
  220. Once all of the correct configuration files are in place, it is time to start the
  221. proxy processes!
  222. #. First, make sure your Salt Master is running.
  223. #. Start the first Salt Proxy, in debug mode, by giving the Proxy Minion process
  224. and ID that matches the config file name created in the `Configuration`_ section.
  225. .. code-block:: bash
  226. salt-proxy --proxyid='esxi-1' -l debug
  227. #. Accept the ``esxi-1`` Proxy Minion's key on the Salt Master:
  228. .. code-block:: bash
  229. # salt-key -L
  230. Accepted Keys:
  231. Denied Keys:
  232. Unaccepted Keys:
  233. esxi-1
  234. Rejected Keys:
  235. #
  236. # salt-key -a esxi-1
  237. The following keys are going to be accepted:
  238. Unaccepted Keys:
  239. esxi-1
  240. Proceed? [n/Y] y
  241. Key for minion esxi-1 accepted.
  242. #. Repeat for the second Salt Proxy, this time we'll run the proxy process as a
  243. daemon, as an example.
  244. .. code-block:: bash
  245. salt-proxy --proxyid='esxi-2' -d
  246. #. Accept the ``esxi-2`` Proxy Minion's key on the Salt Master:
  247. .. code-block:: bash
  248. # salt-key -L
  249. Accepted Keys:
  250. esxi-1
  251. Denied Keys:
  252. Unaccepted Keys:
  253. esxi-2
  254. Rejected Keys:
  255. #
  256. # salt-key -a esxi-1
  257. The following keys are going to be accepted:
  258. Unaccepted Keys:
  259. esxi-2
  260. Proceed? [n/Y] y
  261. Key for minion esxi-1 accepted.
  262. #. Check and see if your Proxy Minions are responding:
  263. .. code-block:: bash
  264. # salt 'esxi-*' test.version
  265. esxi-1:
  266. True
  267. esxi-3:
  268. True
  269. Executing Commands
  270. ==================
  271. Now that you've configured your Proxy Minions and have them responding successfully
  272. to a ``test.version``, we can start executing commands against the ESXi hosts via Salt.
  273. It's important to understand how this particular proxy works, and there are a couple
  274. of important pieces to be aware of in order to start running remote execution and
  275. state commands against the ESXi host via a Proxy Minion: the
  276. `vSphere Execution Module`_, the `ESXi Execution Module`_, and the `ESXi State Module`_.
  277. vSphere Execution Module
  278. ------------------------
  279. The :mod:`Salt.modules.vsphere <salt.modules.vsphere>` is a
  280. standard Salt execution module that does the bulk of the work for the ESXi Proxy
  281. Minion. If you pull up the docs for it you'll see that almost every function in
  282. the module takes credentials (``username`` and ``password``) and a target ``host``
  283. argument. When credentials and a host aren't passed, Salt runs commands
  284. through ``pyVmomi`` or ``ESXCLI`` against the local machine. If you wanted,
  285. you could run functions from this module on any machine where an appropriate
  286. version of ``pyVmomi`` and ``ESXCLI`` are installed, and that machine would reach
  287. out over the network and communicate with the ESXi host.
  288. You'll notice that most of the functions in the vSphere module require a ``host``,
  289. ``username``, and ``password``. These parameters are contained in the Pillar files and
  290. passed through to the function via the proxy process that is already running. You don't
  291. need to provide these parameters when you execute the commands. See the
  292. `Running Remote Execution Commands`_ section below for an example.
  293. ESXi Execution Module
  294. ---------------------
  295. In order for the Pillar information set up in the `Configuration`_ section above to
  296. be passed to the function call in the vSphere Execution Module, the
  297. :mod:`salt.modules.esxi <salt.modules.esxi>` execution module acts
  298. as a "shim" between the vSphere execution module functions and the proxy process.
  299. The "shim" takes the authentication credentials specified in the Pillar files and
  300. passes them through to the ``host``, ``username``, ``password``, and optional
  301. ``protocol`` and ``port`` options required by the vSphere Execution Module functions.
  302. If the function takes more positional, or keyword, arguments you can append them
  303. to the call. It's this shim that speaks to the ESXi host through the proxy, arranging
  304. for the credentials and hostname to be pulled from the Pillar section for the ESXi
  305. Proxy Minion.
  306. Because of the presence of the shim, to lookup documentation for what
  307. functions you can use to interface with the ESXi host, you'll want to
  308. look in :mod:`salt.modules.vsphere <salt.modules.vsphere>`
  309. instead of :mod:`salt.modules.esxi <salt.modules.esxi>`.
  310. Running Remote Execution Commands
  311. ---------------------------------
  312. To run commands from the Salt Master to execute, via the ESXi Proxy Minion, against
  313. the ESXi host, you use the ``esxi.cmd <vsphere-function-name>`` syntax to call
  314. functions located in the vSphere Execution Module. Both args and kwargs needed
  315. for various vsphere execution module functions must be passed through in a kwarg-
  316. type manor. For example:
  317. .. code-block:: bash
  318. salt 'esxi-*' esxi.cmd system_info
  319. salt 'exsi-*' esxi.cmd get_service_running service_name='ssh'
  320. ESXi State Module
  321. -----------------
  322. The ESXi State Module functions similarly to other state modules. The "shim" provided
  323. by the `ESXi Execution Module`_ passes the necessary ``host``, ``username``, and
  324. ``password`` credentials through, so those options don't need to be provided in the
  325. state. Other than that, state files are written and executed just like any other
  326. Salt state. See the :mod:`salt.modules.esxi <salt.states.esxi>` state
  327. for ESXi state functions.
  328. The follow state file is an example of how to configure various pieces of an ESXi host
  329. including enabling SSH, uploading and SSH key, configuring a coredump network config,
  330. syslog, ntp, enabling VMotion, resetting a host password, and more.
  331. .. code-block:: yaml
  332. # /srv/salt/configure-esxi.sls
  333. configure-host-ssh:
  334. esxi.ssh_configured:
  335. - service_running: True
  336. - ssh_key_file: /etc/salt/ssh_keys/my_key.pub
  337. - service_policy: 'automatic'
  338. - service_restart: True
  339. - certificate_verify: True
  340. configure-host-coredump:
  341. esxi.coredump_configured:
  342. - enabled: True
  343. - dump_ip: 'my-coredump-ip.example.com'
  344. configure-host-syslog:
  345. esxi.syslog_configured:
  346. - syslog_configs:
  347. loghost: ssl://localhost:5432,tcp://10.1.0.1:1514
  348. default-timeout: 120
  349. - firewall: True
  350. - reset_service: True
  351. - reset_syslog_config: True
  352. - reset_configs: loghost,default-timeout
  353. configure-host-ntp:
  354. esxi.ntp_configured:
  355. - service_running: True
  356. - ntp_servers:
  357. - 192.174.1.100
  358. - 192.174.1.200
  359. - service_policy: 'automatic'
  360. - service_restart: True
  361. configure-vmotion:
  362. esxi.vmotion_configured:
  363. - enabled: True
  364. configure-host-vsan:
  365. esxi.vsan_configured:
  366. - enabled: True
  367. - add_disks_to_vsan: True
  368. configure-host-password:
  369. esxi.password_present:
  370. - password: 'new-bad-password'
  371. States are called via the ESXi Proxy Minion just as they would on a regular minion.
  372. For example:
  373. .. code-block:: bash
  374. salt 'esxi-*' state.sls configure-esxi test=true
  375. salt 'esxi-*' state.sls configure-esxi
  376. Relevant Salt Files and Resources
  377. =================================
  378. - :mod:`ESXi Proxy Minion <salt.proxy.esxi>`
  379. - :mod:`ESXi Execution Module <salt.modules.esxi>`
  380. - :mod:`ESXi State Module <salt.states.esxi>`
  381. - :ref:`Salt Proxy Minion Docs <proxy-minion>`
  382. - :ref:`Salt Proxy Minion End-to-End Example <proxy-minion-end-to-end-example>`
  383. - :mod:`vSphere Execution Module <salt.modules.vsphere>`