Project

General

Profile

Bug #2948

Whitelist additional Provisioning Template Macros

Added by Ronny M almost 6 years ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Category:
Templates
Target version:
Difficulty:
Triaged:
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

If would like to have the following Provisioning Template macro's white listed so they can be used in templates with savemode_render set to true in provisioning settings.
@host.interfaces.size
@host.interfaces.empty


Related issues

Related to Foreman - Bug #3602: Provisioning templates do not support all the documented functionsDuplicate2013-11-07
Related to Boot disk - Support #4184: undefined method 'mask' for Safemode::Jail (NilClass)Closed2014-01-25
Related to Discovery - Bug #9077: Hostname templating does not work with facts_hashClosed2015-01-22

Associated revisions

Revision 13d9564d (diff)
Added by Lukas Zapletal over 4 years ago

Fixes #2948 - added sp_* host attributes to safe mode

Refs #2948 - Add sp_ host attributes to jail test

Revision faeca375 (diff)
Added by Lukas Zapletal over 4 years ago

Fixes #2948 - added sp_* host attributes to safe mode

Refs #2948 - Add sp_ host attributes to jail test

(cherry picked from commit 13d9564d3b64da23aafd0e8dc6d243a8f032dd2c)

History

#1 Updated by Ronny M almost 6 years ago

Forgot to mention that this is about foreman 1.2 and 1.2.1 but I assume that it is valid for older releases as well.

#2 Updated by Ronny M almost 6 years ago

The following macro's also only work if savemode_render is set to false which I would like to have white-listed so I they can be used with savemode_render is true.

@host.interfaces.bmc.first
@host.interfaces.bmc.first.username
@host.interfaces.bmc.first.password
@host.sp_ip
@host.sp_subnet
@host.sp_subnet.mask
@host.sp_subnet.gateway

#3 Updated by Lukas Zapletal almost 6 years ago

  • Category set to Templates
  • Target version set to 1.3.0

Hey Ronny,

go ahead; edit that and test that, it is defined in: lib/foreman/renderer.rb

I see you already edited http://projects.theforeman.org/projects/foreman/wiki/TemplateWriting - it's a bit early for this as the feature is not there yet.

#4 Updated by Ronny M almost 6 years ago

Ok, I will do that and test it.

In my wiki updates there is a note that savemode_render should be set to false for it to work. :)
But I can remove the updates if you wish?
But then the entries about bmc (not made by me) in the wiki should probably also be removed, because they also only work if savemode_render is disabled.

#5 Updated by Lukas Zapletal over 5 years ago

Right I missed the note on the wiki, this is fine. Right. If you need assistance with your contribution, dont hesitate to ping me on IRC! Thank you.

#6 Updated by Lukas Zapletal over 5 years ago

  • Target version changed from 1.3.0 to 1.4.0

#7 Updated by Ronny M over 5 years ago

For some reason I keep getting "http 500 errors" when viewing a template if I try to white-list methods in /usr/share/foreman/lib/foreman/renderer.rb and use them in my provisioning templates.

What I did:

With safemode_render set to false:

Added for example ", :sp_ip" to allowed_helpers as shown below:

allowed_helpers = [ :foreman_url, :grub_pass, :snippet, :snippets, :ks_console, :root_pass, :multiboot, :jumpstart_path, :install_path, :miniroot, :media_path, :sp_ip ]

Restarted everything to make sure changes are effective, also tried a reboot.

Viewing a template is now still ok.

Then added the following line using the template edit button for my host.

  1. <%= @host.sp_ip %>

Viewing the template still ok.

Then set safemode_render to true:

Error 500 when trying to view template and in logging.

Unfortunately no extra information in foreman debug log the explains what went wrong.

Any Ideas what is going wrong?

#8 Updated by Ronny M over 5 years ago

The 1. before <%= @host.sp_ip %> is a hash but replaced by the wiki with .1, and forgot to mention that the right ip address is shown in the template with safemode_render set to false.

#9 Updated by Greg Sutcliffe over 5 years ago

  • Target version deleted (1.4.0)

#10 Updated by Dominic Cleal over 5 years ago

  • Related to Bug #3602: Provisioning templates do not support all the documented functions added

#11 Updated by Greg Sutcliffe over 5 years ago

The bootdisk iPXE example templates also have Safemode problems. Specifically the methods

Redhat.url_for_boot()
Debian.boot_files_uri()

which are used to get direct download links for the kernel/initrd from the install media. Neither work correctly in Safemode. In addtion, Debian.boot_files_uri requires @host.medium as an argument, which also cannot be rendered.

#12 Updated by Dominic Cleal over 5 years ago

host.facts_hash, host.facts_hash['foo'] should also be available.

#13 Updated by Dominic Cleal over 5 years ago

There I some I use in bootdisk too, see #4184.

#14 Updated by Dominic Cleal over 5 years ago

  • Related to Support #4184: undefined method 'mask' for Safemode::Jail (NilClass) added

#15 Updated by Matt Darcy about 5 years ago

puppet_ca_server on hostgroups will also need whitelisting, I'd expect also

ca_server = <%= @host.puppet_ca_server %>
certname = <%= @host.certname %>
environment = <%= @host.environment %>
server = <%= @host.puppetmaster %>

will need to be updated in hostgroups as I believe I'm only getting the error on puppet_ca_server is it's the first one in the list of the puppet.conf snippet.

#16 Updated by Dominic Cleal about 5 years ago

@host.token.nil? in the default iPXE template fails too:

There was an error rendering the Kickstart default iPXE template: undefined method 'nil?' for Safemode::Jail (Token)

#17 Updated by Dominic Cleal over 4 years ago

Dominic Cleal wrote:

@host.token.nil? in the default iPXE template fails too:

There was an error rendering the Kickstart default iPXE template: undefined method 'nil?' for Safemode::Jail (Token)

Fixed in #5708.

#18 Updated by Lukas Zapletal over 4 years ago

  • Related to Bug #9077: Hostname templating does not work with facts_hash added

#19 Updated by Lukas Zapletal over 4 years ago

  • Status changed from New to Assigned
  • Assignee set to Lukas Zapletal

I have reviewed our docs while working on this issue:

http://projects.theforeman.org/projects/foreman/wiki/TemplateWriting/diff?utf8=%E2%9C%93&version=71&version_from=70&commit=View+differences

Also as part of this review, added "facts" alias. Attribute "facts_hash" was never exposed via safemode.

#20 Updated by The Foreman Bot over 4 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2102 added
  • Pull request deleted ()

#21 Updated by Lukas Zapletal over 4 years ago

  • Target version set to 1.7.2

Setting release to 1.7.1 for backporting.

#22 Updated by Lukas Zapletal over 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#23 Updated by Dominic Cleal over 4 years ago

  • Legacy Backlogs Release (now unused) set to 30

Also available in: Atom PDF