File distribution with templating

With file distribution it is easy to play out files. It can be selected to which device or group a file is played out. But sometimes it can be useful to be able to adopt the file according to which group it is distributed to. Let's assume I have a file that should contain a text with a personalized greeting according to which group the device belongs to.

So a hello.txt file looks like this:

    Hello World,
    How are you?

Now there is a device tree with three groups each containing devices:

-> All devices
    -> Oslo
    -> Berlin
    -> London

Now we can use key-value templating on the original file by using Mustache notation with double curly brackets and save the original text file as a template file called hello.tmpl (the name is freely selectable):

    Hello {{city}},
    How are you?

Then we go into file distribution and define that the template (which needs to be uploaded to the file manager) is distributed to the device into the home folder as hello.txt. In addition the "Template" function is checked which allows to define key-value paramters. In this case we use "Oslo" as the value for the key "city"

basic templating

With the next qbee agent run the file hello.txt will be on all devices in the Oslo group with the following text:

    Hello Oslo,
    How are you?

Any time the value is changed the file gets rewritten with the new value expanded in the file. The same can be done with different names for the other groups.

How can this be useful?

This can be used to define configuration in configuration files (for example IP addresses or any other parameter). It can also be used to control scripts in different ways. Please see here for learning how to run a script once or here how to control script parameters. A typical way of using this to define a config file based on group membership can be seen in this example. This uses software management instead of file distribution but the templating works in exactly the same way.

How to use command-to-run?

Any time a new file is created on the device the command to run is called (if there is anything there). This means that the qbee agent triggers this any time there is a change in the key value pairs. This can be used for a lot of things as described above.