How to set variables from a Deploy

From version 0.041, ASYD support to set variables from a “def”, “def.sudo”, “undeploy” or “undeploy.sudo” file.

var <varname> = exec [host] [if <condition>]: command

With this new feature, you can set a variable with the value returned by the exec command (which also supports variables and conditionals). For it to work, the command executed should produce some output.

After setting it you can use the variable anywere normally, by calling <%VAR:varname%>.

If a variable with the same name exists, it’s value will be overwitten with the new value returned by the command.

Installing MySQL Server on Debian with a random password

A great use for this new feature (along others), is to generate random passwords. On this example we’ll show how to install MySQL Server on a Debian host creating a random password and storing it.


The example above generates a 12 characters random password using /dev/urandom, then stores it on the variable “mysql_password”, and then use that variable for setting the MySQL Server root password and installing it.

This is the output we get from executing it:


After the execution, the variable mysql_password will be stored as a host variable, so you can access it again from other deploy (for example if you wish to do database operations), or just to check it.


You can get the full example from our contrib repository on GitHub!

Leave a Reply

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