An article by Dominique, our head of technology.
Ressources
cdist is located on github.com/ungleich/cdist.
A small overview of cdist you can find here.
The man pages about parameters you find here or on your cloned cdist git repository.
Overview
Every cdist type can contain different kind of parameters:
- Optional
- Optional_multiple
- Required
- Required_multiple
- Boolean
These parameters allow you to give a type some required or optional information.
(e.g. The source of a file which should be sent = required. The destination owner = optional)
Location
The definition of parameters are located in
$HOME/.cdist/type/__TYPE_NAME/parameter/
Types of parameters
Optional
The optional parameter is, like the name states, only optional. This means the type will run without providing this parameter.
To define optional parameters, write the name of the parameter on each line in the file:
echo "owner" >
$HOME/.cdist/type/__TYPE_NAME/parameter/optional
If you want to define a parameter which accepts more than one value use
echo "options" > $HOME/.cdist/type/__TYPE_NAME/parameter/optional_multiple
instead.
Required
Required parameter are obviously required by the type. If the type doesn't get the required parameter, cdist will exit with an error.
Defining required parameters is like the optional parameters.
So write the name of the parameter on each line in the file:
echo "owner" >
$HOME/.cdist/type/__TYPE_NAME/parameter/required
And for multiple required parameters:
echo "options" >
$HOME/.cdist/type/__TYPE_NAME/parameter/required_multiple
Boolean
Boolean parameters are used for parameters which are either yes or no.
In cdist the Boolean type inverts a default value from the type.
For example: There could be a cdist type which install a web server. If no Boolean parameter is provided, the type will configure the web server with ssl. If the Boolean parameter --no-ssl is used, cdist configures the web server without ssl.
Defining Boolean parameter is done like before in the file:
echo "no-ssl"
$HOME/.cdist/type/__TYPE_NAME/parameter/boolean
Default values
For optional parameters you can set default values, which are set if no parameter is provided.
First create a sub directory in your parameter folder:
mkdir $HOME/.cdist/type/__TYPE_NAME/parameter/default
Then for every optional parameter creates a separate file (named like the parameter) and write the default value in it:
echo "tester" > $HOME/.cdist/type/__TYPE_NAME/parameter/default/owner
Using parameters in a type
The values of the provided parameters are stored in files, each for one parameter.
In a type you can get the values by using cat on the $__object/parameter/PARAMETER file.
For required and predefined optional parameters you can use:
owner="$(cat $__object/parameter/owner)"
(This command stores the output from cat in the variable owner)
For only optional parameters use an if before:
if [ -f "$__object/parameter/logdirectory" ]; then
logdirectory="$(cat "$__object/parameter/logdirectory")"
fi
(These lines first check if the file exists (and has type=file), and if it exists, store the output from cat to the variable)
And for multiple parameters use a for loop:
if [ -f "$__object/parameter/server_alias" ]; then
for alias in $(cat "$__object/parameter/server_alias"); do
echo $alias > /some/where/useful
done
fi
(These lines first check if the file exists (and has type=file), if yes, it takes line by line and saves it into another file.
More information
If you have trouble or need more information, visit our github page or write us an email!