The gencode scripts
An article by Dominique, our head of technology.
Cdist is located on github.
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.
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:
The gencode scripts are placed in the types directory.
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
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
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