Project

General

Profile

Actions

Bug #2948

closed

Whitelist additional Provisioning Template Macros

Added by Ronny M over 10 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Category:
Templates
Target version:
Difficulty:
Triaged:
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 3 (0 open3 closed)

Related to Foreman - Bug #3602: Provisioning templates do not support all the documented functionsDuplicateJason Dillaman11/07/2013Actions
Related to Boot disk - Support #4184: undefined method 'mask' for Safemode::Jail (NilClass)Closed01/25/2014Actions
Related to Discovery - Bug #9077: Hostname templating does not work with facts_hashClosedLukas Zapletal01/22/2015Actions
Actions #1

Updated by Ronny M over 10 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.

Actions #2

Updated by Ronny M over 10 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

Actions #3

Updated by Lukas Zapletal over 10 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.

Actions #4

Updated by Ronny M over 10 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.

Actions #5

Updated by Lukas Zapletal over 10 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.

Actions #6

Updated by Lukas Zapletal over 10 years ago

  • Target version changed from 1.3.0 to 1.4.0
Actions #7

Updated by Ronny M over 10 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?

Actions #8

Updated by Ronny M over 10 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.

Actions #9

Updated by Greg Sutcliffe over 10 years ago

  • Target version deleted (1.4.0)
Actions #10

Updated by Dominic Cleal over 10 years ago

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

Updated by Greg Sutcliffe over 10 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.

Actions #12

Updated by Dominic Cleal about 10 years ago

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

Actions #13

Updated by Dominic Cleal about 10 years ago

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

Actions #14

Updated by Dominic Cleal about 10 years ago

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

Updated by Matt Darcy about 10 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.

Actions #16

Updated by Dominic Cleal about 10 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)
Actions #17

Updated by Dominic Cleal about 9 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.

Actions #18

Updated by Lukas Zapletal about 9 years ago

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

Updated by Lukas Zapletal about 9 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.

Actions #20

Updated by The Foreman Bot about 9 years ago

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

Updated by Lukas Zapletal about 9 years ago

  • Target version set to 1.7.2

Setting release to 1.7.1 for backporting.

Actions #22

Updated by Lukas Zapletal about 9 years ago

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

Updated by Dominic Cleal about 9 years ago

  • translation missing: en.field_release set to 30
Actions

Also available in: Atom PDF