Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

octocalog-diff seems to resolve scope differently from puppet #145

Open
markdanko opened this issue Aug 11, 2017 · 2 comments
Open

octocalog-diff seems to resolve scope differently from puppet #145

markdanko opened this issue Aug 11, 2017 · 2 comments

Comments

@markdanko
Copy link

Description of problem
tl;dr
puppet and octocatalog diff don't read things the same way.

in puppet I have module (foo) which calls a template in another module (bar)
a var declared in module bar is not accessible to the template with @ in octocalog-diff but in puppet it is accessible.

in puppet this works fine but in octocatalog-diff
"cluster_name" : "<%= @cluster_name.downcase %>",
If I change it to scope['bar::cluster_name'].downcase it works in octocalog-diff

  • What did you do?
    I have a module
    foo:

which has:

define service_definition (
$service = $title,
$template = "${service}/${service}.json.erb",
$enabled = true,
$watch_config = '',
) {
$service_def_path = "/etc/somepath/servicedefs/${service}.json"
if $enabled and ($::foo::version != 'absent') {
file { $service_def_path:
ensure => present,

content => inline_template($template),

  content => template($template),
  owner   => 'root',
  group   => 'root',
  mode    => '0644',
  require => Package['foo'],

}

In puppet when I give it service bar it works fine,
but in your tool I get:

Error: Failed to compile catalog for node bas Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Failed to parse template bar/bar.json.erb:
Filepath: /var/folders/sp/r687p5j51y106yn0gb4vynwm0000gn/T/d20170811-19384-1ldupto/environments/production/modules/ibar/templates/bar.json.erb
Line: 7
Detail: undefined method `downcase' for nil:NilClass
at /var/folders/sp/r687p5j51y106yn0gb4vynwm0000gn/T/d20170811-19384-1ldupto/environments/production/modules/foo/manifests/init.pp:77:18 at /var/folders/sp/r687p5j51y106yn0gb4vynwm0000gn/T/d20170811-19384-1ldupto/environments/production/modules/bar/manifests/init.pp:59 on node bas

Line: 7 is
"cluster_name" : "<%= @cluster_name.downcase %>",
If I change it to scope['bar::cluster_name'].downcase it works fine for octocatalog--diff.

  • What happened?
    octocalog-diff did not work like puppet

  • What did you expect to happen?

octocalog-diff should work like puppet

  • How can someone reproduce the problem?
    any time one module calls another modules, template, and that template uses vars define in the second module

Command used and debugging output
If you feel this will help I will add it.

Platform and version information

  • Your OS:
    mac 10.12.5 (16F73) for octocatalog-diff

16.6.0 Darwin puppet master

  • Your Ruby version:
    ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16] ( on octocatalog-diff host

  • Your version of Puppet:
    puppet --version
    3.8.6
    ruby --version
    ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux ( on puppet master)

  • Your version of octocatalog-diff:

Do the tests pass from a clean checkout?

yes

Anything else to add that you think will be helpful?
is this expected/etc ?

@kpaulisse
Copy link
Contributor

kpaulisse commented Oct 10, 2017

his actually looks to me like maybe you're encountering a bug with Puppet 3.x that happens to be working the way you want. Unless @cluster_name is being set at the top level (e.g. in a parameter or fact), I don't think that a template should recognize variables from a module you haven't explicitly included, and even then I think you'd need to re-declare that variable in the current manifest to make that work.

From the 3.8 docs (link):

All variables in the current scope (including global variables) are passed to templates as Ruby instance variables, which begin with “at” signs (@). If you can access a variable by its short name in the surrounding manifest, you can access it in the template by replacing its $ sign with an @. So $os becomes @os, $trusted becomes @trusted, etc.

This is the most legible way to access variables, but it doesn’t support variables from other scopes. For that, you need to use the scope object.

Fully qualifying your variables with the scope is probably the best idea here, definitely for forward compatibility.

@vinzent
Copy link
Contributor

vinzent commented May 31, 2018

@markdanko I don't think octocatalog-diff resolves anything other than "puppet" - as it calls puppet to compile. There were bugs in Puppet 3 which allowed to resolve variables that actually shouldn't be available.

Anyway I would recommend you to use the new EPP instead of the (deprecated and not well specified) ERB.

https://puppet.com/docs/puppet/5.5/lang_template_epp.html (Available since Puppet 4)

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

No branches or pull requests

3 participants