1
0

vars.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ===============================
  2. SLS Template Variable Reference
  3. ===============================
  4. The template engines available to sls files and file templates come loaded
  5. with a number of context variables. These variables contain information and
  6. functions to assist in the generation of templates. See each variable below
  7. for its availability -- not all variables are available in all templating
  8. contexts.
  9. Salt
  10. ====
  11. The `salt` variable is available to abstract the salt library functions. This
  12. variable is a python dictionary containing all of the functions available to
  13. the running salt minion. It is available in all salt templates.
  14. .. code-block:: jinja
  15. {% for file in salt['cmd.run']('ls -1 /opt/to_remove').splitlines() %}
  16. /opt/to_remove/{{ file }}:
  17. file.absent
  18. {% endfor %}
  19. Opts
  20. ====
  21. The `opts` variable abstracts the contents of the minion's configuration file
  22. directly to the template. The `opts` variable is a dictionary. It is available
  23. in all templates.
  24. .. code-block:: jinja
  25. {{ opts['cachedir'] }}
  26. The ``config.get`` function also searches for values in the `opts` dictionary.
  27. Pillar
  28. ======
  29. The `pillar` dictionary can be referenced directly, and is available in all
  30. templates:
  31. .. code-block:: jinja
  32. {{ pillar['key'] }}
  33. Using the ``pillar.get`` function via the `salt` variable is generally
  34. recommended since a default can be safely set in the event that the value
  35. is not available in pillar and dictionaries can be traversed directly:
  36. .. code-block:: jinja
  37. {{ salt['pillar.get']('key', 'failover_value') }}
  38. {{ salt['pillar.get']('stuff:more:deeper') }}
  39. Grains
  40. ======
  41. The `grains` dictionary makes the minion's grains directly available, and is
  42. available in all templates:
  43. .. code-block:: jinja
  44. {{ grains['os'] }}
  45. The ``grains.get`` function can be used to traverse deeper grains and set
  46. defaults:
  47. .. code-block:: jinja
  48. {{ salt['grains.get']('os') }}
  49. saltenv
  50. =======
  51. The `saltenv` variable is available in only in sls files when gathering the sls
  52. from an environment.
  53. .. code-block:: jinja
  54. {{ saltenv }}
  55. sls
  56. ====
  57. The `sls` variable contains the sls reference value, and is only available in
  58. the actual SLS file (not in any files referenced in that SLS). The sls
  59. reference value is the value used to include the sls in top files or via the
  60. include option.
  61. .. code-block:: jinja
  62. {{ sls }}
  63. slspath
  64. =======
  65. The `slspath` variable contains the path to the directory of the current sls
  66. file. The value of `slspath` in files referenced in the current sls depends on
  67. the reference method. For jinja includes `slspath` is the path to the current
  68. directory of the file. For salt includes `slspath` is the path to the directory
  69. of the included file.
  70. .. code-block:: jinja
  71. {{ slspath }}