Development, Guides

Working with variables and default values

We have just released ASYD v1.1.0.! Among other improvements, it’s now possible to add default values to the custom variables in deploys and configuration files.

This means you can hard-code default values for your variables when writing a deploy. In case the variable is not set either on host or hostgroup level, ASYD will use the specified default value.

Thanks to this functionality we can create standardized deploys which can be used by anyone, yet configurable using variables.

The syntax extends the normal functioning of ASYD variables, and can be used in the same fashion as before, with the extra “default:” option:

<%VAR:varname%>

<%VAR:varname, default: value%>

The first one won’t use any default value, while the second will use “value” as it’s default.

Web server example

You are writing a deploy which specifies a port for a nginx web server. You want this nginx server to default on port “80” but give the option to override on host or hostgroup level.

On the configuration file you would write:

listen <%VAR:http_port, default: 80%>;

As a result, the configuration file will state “listen 80;” unless the variable “http_port” is defined. If you want to override this default value just set the variable “http_port” on a host or hostgroup with a different value, for instance, if you want certain server to use port “8080” instead.

Leave a comment below with your thoughts on this new feature, and if you got any suggestions you would like to see implemented next 😉

Leave a Reply

Your email address will not be published. Required fields are marked *