Skip to content

Conversation

@maximiliankolb
Copy link
Contributor

What changes are you introducing?

Users should never clone and edit templates. Instead, if they really need to run custom code before or after registration or provisioning workflows, they should use "custom pre" and "custom post" snippets as documented. This way they do not lose support by the community/vendor.

Also, there's configuration management.

Why are you introducing these changes? (Explanation, links to references, issues, etc.)

Fixes #4256

Anything else to add? (Considerations, potential downsides, alternative solutions you have explored, etc.)

Should we also drop the hint about cloning and editing in guides/common/modules/proc_setting-up-job-templates.adoc?

Contributor checklists

  • I am okay with my commits getting squashed when you merge this PR.
  • I am familiar with the contributing guidelines.

Please cherry-pick my commits into:

  • Foreman 3.16/Katello 4.18 (Satellite 6.18)
  • Foreman 3.15/Katello 4.17
  • Foreman 3.14/Katello 4.16 (Satellite 6.17; orcharhino 7.4)
  • Foreman 3.13/Katello 4.15 (EL9 only)
  • Foreman 3.12/Katello 4.14 (Satellite 6.16; orcharhino 7.2 on EL9 only; orcharhino 7.3)
  • Foreman 3.11/Katello 4.13 (orcharhino 6.11 on EL8 only; orcharhino 7.0 on EL8+EL9; orcharhino 7.1 with Leapp)
  • Foreman 3.10/Katello 4.12
  • Foreman 3.9/Katello 4.11 (Satellite 6.15; orcharhino 6.8/6.9/6.10)
  • We do not accept PRs for Foreman older than 3.9.

@github-actions github-actions bot added Needs tech review Requires a review from the technical perspective Needs style review Requires a review from docs style/grammar perspective Needs testing Requires functional testing labels Sep 24, 2025
@github-actions
Copy link

github-actions bot commented Sep 24, 2025

The PR preview for 5ffa48f is available at theforeman-foreman-documentation-preview-pr-4296.surge.sh

The following output files are affected by this PR:

show diff

show diff as HTML

@Lennonka
Copy link
Contributor

Should we also drop the hint about cloning and editing in job templates

I'm not sure if job templates support custom snippets the same way as provisioning templates. That would require further research.

Copy link
Contributor

@Lennonka Lennonka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change LGTM, but I would appreciate a tech ack.

@Lennonka Lennonka added style review done No issues from docs style/grammar perspective and removed Needs style review Requires a review from docs style/grammar perspective labels Sep 26, 2025
@maximiliankolb maximiliankolb removed the Needs testing Requires functional testing label Sep 26, 2025
@maximiliankolb maximiliankolb force-pushed the fix_4256_custom_snippets branch from 288b4bf to 7fe05f7 Compare October 10, 2025 06:42
Users should never clone and edit templates. Instead, if they really
need to run custom code before or after registration or provisioning
workflows, they should use "custom pre" and "custom post" snippets as
documented. This way they do not lose support by the community/vendor.

Also, there's configuration management.

Fixes theforeman#4256
@maximiliankolb maximiliankolb force-pushed the fix_4256_custom_snippets branch from 7fe05f7 to 5ffa48f Compare December 17, 2025 10:12
@maximiliankolb
Copy link
Contributor Author

Rebased to HEAD of "master" and resolved all merge conflicts.

@stejskalleos Can you please review my PR? Does it make sense to you from a technical perspective?

Comment on lines -21 to -22
If you require modification to an original template, clone the template, edit the clone, and associate the clone instead of the original template.
For more information, see xref:running-custom-code-during-host-provisioning-by-using-web-ui[].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should recommend users to not clone provisioning template, since those are locked by default and how users would add pre/post snippets to it without cloning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to not clone and edit at all. Instead, users can write "custom pre" and "custom post" snippets that are automatically picked up by supported templates. Example in foreman on "develop":

app/views/unattended/provisioning_templates/provision/kickstart_default.erb
222:<%= snippet_if_exists(template_name + " custom pre") %>

So locked template pick up user-provided snippets if present, which avoids the whole "clone+edit and lose updates/support" kinda situation.

Copy link
Contributor

@Lennonka Lennonka Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Max is saying, the custom pre/post snippets do not have to be added to templates because the code is there by default (example). If the snippets don't exist, nothing happens. Once the user creates them, the templates pick them up automatically.

Therefore, the user doesn't have to clone and edit templates to add the snippets to the provisioning process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stejskalleos Can you please ack this ^^ and this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the snippets don't exist, nothing happens. Once the user creates them, the templates pick them up automatically.

Correct.

Therefore, the user doesn't have to clone and edit templates to add the snippets to the provisioning process.

Also correct.

====
You can use the original templates shipped in {Project} as described below.
If you require modification to an original template, clone the template, edit the clone, and associate the clone instead of the original template.
For more information, see xref:running-custom-code-during-host-provisioning-by-using-web-ui[].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't a correct link for the clone guide, which should be either https://docs.theforeman.org/nightly/Provisioning_Hosts/index-katello.html#cloning-provisioning-templates, right?
cc @stejskalleos @ShimShtein

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this relevant when we're removing it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs tech review Requires a review from the technical perspective style review done No issues from docs style/grammar perspective

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recommend custom pre/custom post snippets in favor of cloning+editing templates

4 participants