Using Salt Variables

Using Salt Variables

I am relatively new to Salt, YAML, Jinja etc. Learning as I go. I have a yaml file being used with SaltStack to distribute several files to servers. A few of the files have a version indicator in the name. I would like to enter this once in the yaml file and then use it in name variables throughout the file. I’m not clear from searching if this is possible?

Example. I want to distribute a set of files to install DB2 version 11 fixpack 2. I have an install script, a configure script, a response file and a zip file with “fp2” in the name. I’d like to define a “ver” variable at the top of the yaml and then use it when defining the other filenames. Is this possible?

1 Answer

You can create a variable on the top of your state file using jinja format,

{% set variable_name = 'variable_value' %}

and then use {{ }} to render it like, {{ variable_name }}

Or if you want to use variable in a logic or within a loop,

{% if variable_name %} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.