1
0

demo.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 this file:
  41. .. code-block:: yaml
  42. p8000.sls
  43. ---------
  44. proxy:
  45. proxytype: rest_sample
  46. url: http://<IP your REST listens on>:port
  47. In other words, if your REST service is listening on port 8000 on 127.0.0.1
  48. the 'url' key above should say ``url: http://127.0.0.1:8000``
  49. 4. Make sure your salt-master is running.
  50. 5. Start the salt-proxy in debug mode
  51. .. code-block:: bash
  52. salt-proxy --proxyid=p8000 -l debug
  53. 6. Accept your proxy's key on your salt-master
  54. .. code-block:: bash
  55. salt-key -y -a p8000
  56. The following keys are going to be accepted:
  57. Unaccepted Keys:
  58. p8000
  59. Key for minion p8000 accepted.
  60. 7. Now you should be able to ping your proxy. When you ping, you should see
  61. a log entry in the terminal where the REST service is running.
  62. .. code-block:: bash
  63. salt p8000 test.version
  64. 8. The REST service implements a degenerately simple pkg and service provider as
  65. well as a small set of grains. To "install" a package, use a standard
  66. ``pkg.install``. If you pass '==' and a verrsion number after the package
  67. name then the service will parse that and accept that as the package's
  68. version.
  69. 9. Try running ``salt p8000 grains.items`` to see what grains are available. You
  70. can target proxies via grains if you like.
  71. 10. You can also start and stop the available services (apache, redbull, and
  72. postgresql with ``service.start``, etc.
  73. 11. States can be written to target the proxy. Feel free to experiment with
  74. them.