Printing labels after provisioning

Hello.

I’m new here so i hope that my question is in right category.
I have working instance puppet+foreman, where provisioning of new hosts is made. I would like to print labels (barcodes etc.) for every new provisioned host after installation when this host is ready. Printing is quite easy, while i need only to send a label template to printer using ftp and then comes new label.
My question is, how can i trigger this situation the right way/easy way? Parse logs and look after ‘signed certificate’ for example or maybe something else? Unfortunately i don’t have too much experience with puppet/foreman so i don’t know what solution would be the best one.

Thanks for any hints.

Welcome :slight_smile:

You could take a look at this plugin (Foreman Hooks) that is designed to trigger custom scripts on certain events within Foreman. Since I’m not very familiar with it, I’m uncertain which event would be the correct on (I guess host/managed after_commit postcreate) but I do think this plugin should be the way to go.

Regards

Hooks can definitely be used for this, host/managed/after_build is likely the hook you want to use.
You might also be interested in the foreman datacenter plugin that allows auto-generating QR codes for various hardware devices, but I think it is a bit out of date and incompatible with the latest foreman versions (but @Zenya would likely know the current status better)

Foreman Hooks looks promising. It might be what i’m looking for.
We create for every host unique id and it is saved as a fact value for that host. It will be printed too.
Thanks for your help, now i will look deeper into hooks :slight_smile:

When anyone else will have some suggestion then i will be happy to learn something new.

Hi!
We released foreman_datacenter for foreman 1.21 and 1.22, so plugin works well with new versions :slight_smile:

1 Like

I created hook script in /usr/share/foreman/config/hooks/host/managed/after_provision/10_print_label.sh. It works, script is executed properly, I can receive all data from HOOK_OBJECT_FILE. Foreman works on CentOS host.

Script’s content is here: https://hastebin.com/qarogebozi.bash
All is executed by foreman user and all works in /usr/share/foreman/tmp so there is no problems with permissions etc.

At the end I’m trying to send the data to printer, but it seems that ftp command that I’m using doesn’t get variables. When I echo all variables before ftp executing then I got correct values.
It is strange, because when I do the same in terminal then it works, when I execute it as standalone bash script it works too, but as hook script it doesn’t.
I thought to create bash script at the end and execute it but that isn’t pretty solution.
Maybe there is some syntax error I don’t see.

I will be glad if anyone can take a look.

Have a good day