Configure Windows and Linux with Single Salt Module

If OS is Windows, the path is ‘C:\tero’. If OS is Linux, the path is ‘/tmp/tero’. You can use conditionals to create Salt modules that work in multiple operating systems.

Basic Ideas

  • Put conditional logic in the beginning of your state (SLS)
  • Write in one environment (e.g. Ubuntu) first, then add conditions
  • Check generated YAML with state.show_sls
  • If Linux and Windows versions have nothing in common, write separate modules.

/srv/salt/hello/init.sls

{% if "Windows" == grains["os"] %}
{%      set hellofile = "C:\hellotero.txt" %}
{% else %}
{%      set hellofile = "/tmp/hellotero.txt" %}
{% endif %}
{{ hellofile }}:
 file.managed:
 - source: salt://hello/hellotero.txt

View Generated SLS

$ sudo salt '*' state.show_sls hello --out yaml

See Also

Control Windows with Salt

Posted in Uncategorized | Tagged , , , , , , , , , , | Comments Off on Configure Windows and Linux with Single Salt Module

Comments are closed.