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

How to access hiera data from ERB template? #9534

Open
akomakom opened this issue Dec 18, 2024 · 0 comments
Open

How to access hiera data from ERB template? #9534

akomakom opened this issue Dec 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@akomakom
Copy link

Describe the Bug

Puppet Documentation suggests that it is possible to access variables from module ERB templates via the scope['variable_name'] syntax. It is unclear whether that only works for module variables, eg:

class module_name {
    $var1 = 3 # This works
}

or also for hiera-defined variables, eg in module_name/data/common.yaml:

module_name::var1: 3 # This does not work

Expected Behavior

This ERB template should work:

This is a value: <%= scope['module_name::var1']%>

Steps to Reproduce

Steps to reproduce the behavior:

Create a puppet module with the following files:

  • module_name/templates/test.erb
This is a value: <%= scope['module_name::var1']%>
  • module_name/hiera.yaml
---
version: 5

defaults:
  datadir: data
  data_hash: yaml_data

hierarchy:
  - name: "common"
    path: "common.yaml"
  • module_name/data/common.yaml:
This is a value: <%= scope['module_name::var1']%>
  • module_name/manifests/init.pp:
   file { '/some/test':
     content => template("$module_name/test.erb")
   }

Environment

  • Version Puppetserver 8.7.0
  • Platform Redhat 9

Additional Context

I have tried scope['var1'], scope.lookupvar( <full and short name>0, etc.
I can only resolve the value in a template if it is defined as an explicit variable in the manifest, eg:
$var1 = $module_name::var1

@akomakom akomakom added the bug Something isn't working label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant