The gencode scripts
An article by Dominique, our head of technology.
Ressources
Cdist is located on github.
A small overview of cdist you can find here. For deeper insights also visit our lastest blog articles cdist types and parameters and The object ID and singleton types.
You can find the man pages about gencode scripts on github https://github.com/ungleich/cdist/blob/master/docs/src/cdist-type.rst#writing-the-gencode-script or on your cloned cdist git repository.
Overview
You probably need to run a command directly on your host or the target host to achieve what you want
Example: You want to move a newly generated file to another directory. Or start a small script on the target host.
For this purpose cdist implemented the gencode scripts.
There are two different gencode scripts available:
- gencode-local
- gencode-remote
Location
The gencode scripts are placed in the types directory.
$HOME/.cdist/type/__new_type/gencode-local
$HOME/.cdist/type/__new_type/gencode-remote
Use of gencode scripts
Gencode scripts are not the scripts which gets executed on the machine (local- nor target host). Only the output of the gencode scripts gets executed.
This means if you want to run a command with the gencode script, you have to echo it out to stdout:
echo "touch /tmp/testing_file"
This will create an empty file on the target host. But see, that in the gencode script, the command to run on the target host gets an echo in before.
For debugging it is good to use diagnostic messages write out to stderr:
echo "ERROR: Something bad happend" >&2
Tips
Keep in mind, the echoed commands doesn't get executed in the same order as they are in the gencode files.
It sometimes is helpful to use some if-statements. Like if you want to restart dovecot after the config files got applied.
if grep -q "^__file/etc/dovecot" "$__messages_in"; then
echo /etc/init.d/dovecot restart
fi
Different gencode scripts
The only difference in the two gencode script is the location where the code gets executed.
- gencode-local: Code gets executed on the local machine
- gencode-remote: Code gets executed on the target machine
More information
If you have any trouble or need more information, visit our github page or write us an email!