demo.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. .. _proxy-minion-end-to-end-example:
  2. ====================================
  3. Salt Proxy Minion End-to-End Example
  4. ====================================
  5. The following is walkthrough that documents how to run a sample REST service
  6. and configure one or more proxy minions to talk to and control it.
  7. 1. Ideally, create a Python virtualenv in which to run the REST service. This
  8. is not strictly required, but without a virtualenv you will need to install
  9. ``bottle`` via pip globally on your system
  10. 2. Clone https://github.com/saltstack/salt-contrib
  11. and copy the contents of the directory ``proxyminion_rest_example``
  12. somewhere on a machine that is reachable from the machine on which you want to
  13. run the salt-proxy. This machine needs Python 2.7 or later.
  14. 3. Install bottle version 0.12.8 via pip or easy_install
  15. .. code-block:: bash
  16. pip install bottle==0.12.8
  17. 4. Run ``python rest.py --help`` for usage
  18. 5. Start the REST API on an appropriate port and IP.
  19. 6. Load the REST service's status page in your browser by going to the IP/port
  20. combination (e.g. http://127.0.0.1:8000)
  21. 7. You should see a page entitled "Salt Proxy Minion" with two sections,
  22. one for "services" and one for "packages" and you should see a log entry in
  23. the terminal where you started the REST process indicating that the index
  24. page was retrieved.
  25. .. image:: /_static/rest_status_screen.png
  26. Now, configure your salt-proxy.
  27. 1. Edit ``/etc/salt/proxy`` and add an entry for your master's location
  28. .. code-block:: yaml
  29. master: localhost
  30. 2. On your salt-master, ensure that pillar is configured properly. Select an ID
  31. for your proxy (in this example we will name the proxy with the letter 'p'
  32. followed by the port the proxy is answering on). In your pillar topfile,
  33. place an entry for your proxy:
  34. .. code-block:: yaml
  35. base:
  36. 'p8000':
  37. - p8000
  38. This says that Salt's pillar should load some values for the proxy ``p8000``
  39. from the file ``/srv/pillar/p8000.sls`` (if you have not changed your default pillar_roots)
  40. 3. In the pillar root for your base environment, create the ``p8000.sls`` file with the
  41. following contents:
  42. .. code-block:: yaml
  43. proxy:
  44. proxytype: rest_sample
  45. url: http://<IP your REST listens on>:port
  46. In other words, if your REST service is listening on port 8000 on 127.0.0.1
  47. the 'url' key above should say ``url: http://127.0.0.1:8000``
  48. 4. Make sure your salt-master is running.
  49. 5. Start the salt-proxy in debug mode
  50. .. code-block:: bash
  51. salt-proxy --proxyid=p8000 -l debug
  52. 6. Accept your proxy's key on your salt-master
  53. .. code-block:: bash
  54. salt-key -y -a p8000
  55. The following keys are going to be accepted:
  56. Unaccepted Keys:
  57. p8000
  58. Key for minion p8000 accepted.
  59. 7. Now you should be able to ping your proxy. When you ping, you should see
  60. a log entry in the terminal where the REST service is running.
  61. .. code-block:: bash
  62. salt p8000 test.version
  63. 8. The REST service implements a degenerately simple pkg and service provider as
  64. well as a small set of grains. To "install" a package, use a standard
  65. ``pkg.install``. If you pass '==' and a verrsion number after the package
  66. name then the service will parse that and accept that as the package's
  67. version.
  68. 9. Try running ``salt p8000 grains.items`` to see what grains are available. You
  69. can target proxies via grains if you like.
  70. 10. You can also start and stop the available services (apache, redbull, and
  71. postgresql with ``service.start``, etc.
  72. 11. States can be written to target the proxy. Feel free to experiment with
  73. them.