Hammer template import directory

Problem:

I need to import provisioning templates and snippets copied into place by puppet when provisioning new foreman servers.

Expected outcome:

Import templates using hammer and find them in the web ui after I’m done with hammer.

Foreman and Proxy versions:
3.4

Foreman and Proxy plugin versions:

Distribution and version:

Redhat 8 server

Hi, with cobbler we were able to just dump files into cobbler kickstarts and they would appear in the web front end. At first I thought this would happen with foreman and could have sworn it worked with one test file with .erb extension after finding where the default foreman provisioning templates were located.

So I had puppet copy a bunch of files over to /usr/share/foreman/app/views/unattended/provisioning_templates/provision as well as snippet. I included the <%# -%> comments which I though somehow picked up the relevant info, but I’m not sure how foreman works. I also set organization and location to anything. Still no dice. Example below.

So do I need to use hammer to import them into the database?
If so is there a way to grab entire directories of snippets and kickstarts at once? I saw an older post that used hammer import-templates --dirname but now it seems that command is deprecated in favour of “hammer template import --file” and it seems like I’d have to do one file at a time? Am I missing something. Is there a --dirname option or something similar? I suppose i could set up some sort of ruby do each thing in puppet to cycle through a large list of our snippets and pass names to the hammer command in a loop, but grabbing them all at once with one command from a directory would be a lot easier.

Sorry if this is unclear. I’ll follow up if clarification is needed. With puppet I can subscribe to the folder and if it detects a change it can notify an exec that runs the hammer import command.

Other relevant data:
Example header in snippet file

<%#
kind: snippet
name: mfe_add_custom_facts_prole_render
model: ProvisioningTemplate
snippet: true
description: |
Set role to render in puppet facts.
-%>

The hammer import-templates command comes from the Foreman templates plugin.
I have linked the docs so you can can take a look at it. According to the docs, the plugin supports syncing from directories. We use it ourselfs to sync templates from a git repository directly and that works very well.
From your problem description, I assume this plugin should solve your requirements.

1 Like

Oh okay, great.

Thank you so much for your feedback. I’ll look at importing that plugin today and hopefully be able to add it automatically to any future foreman servers that are provisioned through puppet.

That will make my life much easier :slight_smile:

For anyone interested the command to add the import-templates plugin was:

foreman-installer --enable-foreman-cli-templates --foreman-db-password=yourforman_db_password

And I now see it and the --dirname option.