FAQ
Hi,

I'm having a problem accessing Hiera data from within templates. Yes, I
know this is not the recommended way to access Hiera data, but in my use
case I think it will be easier overall.

In manifests, this code works:

{
    ip => hiera('jrs_config_server1'),
}

In a template, part of the same module as the manifest, this does not work:

ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>

It fails with this error:

Could not find data item jrs_config_server1 in any Hiera data file and
no default supplied

The value of " jrs_config_server1" is in Hiera, specific to the fqdn of
the node. I'm struggling to see why it would not be working. Any ideas?

Cheers,
Jonathan

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jon Ward at May 10, 2013 at 1:25 pm
    Hi,

    Have you tried doing the Hiera lookup on the command line to double check
    it can be read?

    $ hiera -d -c /path/to/hiera.yaml jrs_config_server1 fqdn=hostname
    >

    Cheers,

    Jon
    On Friday, May 10, 2013 12:18:22 PM UTC+1, Jonathan Gazeley wrote:

    Hi,

    I'm having a problem accessing Hiera data from within templates. Yes, I
    know this is not the recommended way to access Hiera data, but in my use
    case I think it will be easier overall.

    In manifests, this code works:

    {
    ip => hiera('jrs_config_server1'),
    }

    In a template, part of the same module as the manifest, this does not
    work:

    ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>

    It fails with this error:

    Could not find data item jrs_config_server1 in any Hiera data file and
    no default supplied

    The value of " jrs_config_server1" is in Hiera, specific to the fqdn of
    the node. I'm struggling to see why it would not be working. Any ideas?

    Cheers,
    Jonathan
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jonathan Gazeley at May 10, 2013 at 2:46 pm
    Hi Jon,

    Thanks for your tip. I had made a typo in my yaml which debug mode
    picked up. I fixed it, and now your command works when run on the
    puppetmaster but the same error persists when the variable is accessed
    either from a manifest or from a template during a puppet agent run.

    I'm wondering if it might be something to do with the agents not syncing
    the hiera data store, perhaps? I'm new to hiera...

    Cheers,
    Jonathan


    On 10/05/13 14:25, Jon Ward wrote:
    Hi,

    Have you tried doing the Hiera lookup on the command line to double
    check it can be read?

    $ hiera -d -c /path/to/hiera.yaml jrs_config_server1 fqdn=hostname


    Cheers,

    Jon

    On Friday, May 10, 2013 12:18:22 PM UTC+1, Jonathan Gazeley wrote:

    Hi,

    I'm having a problem accessing Hiera data from within templates.
    Yes, I
    know this is not the recommended way to access Hiera data, but in
    my use
    case I think it will be easier overall.

    In manifests, this code works:

    {
    ip => hiera('jrs_config_server1'),
    }

    In a template, part of the same module as the manifest, this does
    not work:

    ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>

    It fails with this error:

    Could not find data item jrs_config_server1 in any Hiera data file
    and
    no default supplied

    The value of " jrs_config_server1" is in Hiera, specific to the
    fqdn of
    the node. I'm struggling to see why it would not be working. Any
    ideas?

    Cheers,
    Jonathan

    --
    You received this message because you are subscribed to the Google
    Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jon Ward at May 10, 2013 at 3:47 pm
    Try putting the variable in common.yaml at the bottom of the hierarchy and
    see if it gets picked up. If it does then perhaps the value of the fqdn
    fact isn't what you think it is.

    You can also try running puppetmaster in the foreground in debug mode:

    $ puppet master —no-daemonize —debug


    Now when you run puppet you should see the Hiera lookups happening as the
    catalog is compiled, this might help you pinpoint the problem..
    On Friday, May 10, 2013 3:46:28 PM UTC+1, Jonathan Gazeley wrote:

    Hi Jon,

    Thanks for your tip. I had made a typo in my yaml which debug mode
    picked up. I fixed it, and now your command works when run on the
    puppetmaster but the same error persists when the variable is accessed
    either from a manifest or from a template during a puppet agent run.

    I'm wondering if it might be something to do with the agents not syncing
    the hiera data store, perhaps? I'm new to hiera...

    Cheers,
    Jonathan


    On 10/05/13 14:25, Jon Ward wrote:
    Hi,

    Have you tried doing the Hiera lookup on the command line to double
    check it can be read?

    $ hiera -d -c /path/to/hiera.yaml jrs_config_server1 fqdn=hostname


    Cheers,

    Jon

    On Friday, May 10, 2013 12:18:22 PM UTC+1, Jonathan Gazeley wrote:

    Hi,

    I'm having a problem accessing Hiera data from within templates.
    Yes, I
    know this is not the recommended way to access Hiera data, but in
    my use
    case I think it will be easier overall.

    In manifests, this code works:

    {
    ip => hiera('jrs_config_server1'),
    }

    In a template, part of the same module as the manifest, this does
    not work:

    ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>

    It fails with this error:

    Could not find data item jrs_config_server1 in any Hiera data file
    and
    no default supplied

    The value of " jrs_config_server1" is in Hiera, specific to the
    fqdn of
    the node. I'm struggling to see why it would not be working. Any
    ideas?

    Cheers,
    Jonathan

    --
    You received this message because you are subscribed to the Google
    Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to [email protected] <javascript:>.
    To post to this group, send email to [email protected]<javascript:>.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jonathan Gazeley at May 13, 2013 at 11:08 am
    Turns out that the problem was fixed by restarting puppetmaster. I
    hadn't appreciated that this is necessary when the hiera config changes
    - as you don't need to restart puppetmaster to pick up new manifests,
    for instance.

    Thanks for your help anyway!
    Jonathan

    On 10/05/13 16:47, Jon Ward wrote:
    Try putting the variable in common.yaml at the bottom of the hierarchy
    and see if it gets picked up. If it does then perhaps the value of the
    fqdn fact isn't what you think it is.

    You can also try running puppetmaster in the foreground in debug mode:

    $ puppet master —no-daemonize —debug


    Now when you run puppet you should see the Hiera lookups happening as
    the catalog is compiled, this might help you pinpoint the problem..

    On Friday, May 10, 2013 3:46:28 PM UTC+1, Jonathan Gazeley wrote:

    Hi Jon,

    Thanks for your tip. I had made a typo in my yaml which debug mode
    picked up. I fixed it, and now your command works when run on the
    puppetmaster but the same error persists when the variable is
    accessed
    either from a manifest or from a template during a puppet agent run.

    I'm wondering if it might be something to do with the agents not
    syncing
    the hiera data store, perhaps? I'm new to hiera...

    Cheers,
    Jonathan


    On 10/05/13 14:25, Jon Ward wrote:
    Hi,

    Have you tried doing the Hiera lookup on the command line to double
    check it can be read?

    $ hiera -d -c /path/to/hiera.yaml jrs_config_server1
    fqdn=hostname

    Cheers,

    Jon

    On Friday, May 10, 2013 12:18:22 PM UTC+1, Jonathan Gazeley wrote:

    Hi,

    I'm having a problem accessing Hiera data from within
    templates.
    Yes, I
    know this is not the recommended way to access Hiera data, but in
    my use
    case I think it will be easier overall.

    In manifests, this code works:

    {
    ip => hiera('jrs_config_server1'),
    }

    In a template, part of the same module as the manifest, this does
    not work:

    ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>

    It fails with this error:

    Could not find data item jrs_config_server1 in any Hiera data file
    and
    no default supplied

    The value of " jrs_config_server1" is in Hiera, specific to the
    fqdn of
    the node. I'm struggling to see why it would not be working. Any
    ideas?

    Cheers,
    Jonathan

    --
    You received this message because you are subscribed to the Google
    Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to [email protected] <javascript:>.
    To post to this group, send email to [email protected]
    <javascript:>.
    Visit this group at
    http://groups.google.com/group/puppet-users?hl=en
    <http://groups.google.com/group/puppet-users?hl=en>.
    <https://groups.google.com/groups/opt_out>.
    --
    You received this message because you are subscribed to the Google
    Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ti Leggett at May 10, 2013 at 1:40 pm
    Use scope.lookupvar on the variable from the manifest:

    ## Manifest
    class foo (
         $ip = hiera(''jrs_config_server1', ''),
    ) {
    }


    ## Template
    <% ip = scope.lookupvar('foo::ip') -%>
    ...


    On May 10, 2013, at 6:18 AM, Jonathan Gazeley wrote:

    Hi,

    I'm having a problem accessing Hiera data from within templates. Yes, I know this is not the recommended way to access Hiera data, but in my use case I think it will be easier overall.

    In manifests, this code works:

    {
    ip => hiera('jrs_config_server1'),
    }

    In a template, part of the same module as the manifest, this does not work:

    ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>

    It fails with this error:

    Could not find data item jrs_config_server1 in any Hiera data file and no default supplied

    The value of " jrs_config_server1" is in Hiera, specific to the fqdn of the node. I'm struggling to see why it would not be working. Any ideas?

    Cheers,
    Jonathan

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Brian Lalor at May 11, 2013 at 1:29 am

    On May 10, 2013, at 7:18 AM, Jonathan Gazeley wrote:

    ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>
    You're passing in an array; is that intentional?

    --
    Brian Lalor
    [email protected]


    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dan White at May 11, 2013 at 2:29 am
    http://docs.puppetlabs.com/guides/templating.html#using-functions-within-templates

    The arguments of the function must be provided as an array, even if there is only one argument.

    However, (and I am just discovering this myself),

    http://docs.puppetlabs.com/hiera/1/puppet.html#using-the-lookup-functions-from-templates

    Using the Lookup Functions From Templates

    In general, don’t use the Hiera functions from templates. That pattern is too obscure, and will hurt your code’s maintainability — if a co-author of your code needs to change the Hiera invocations and is searching.pp files for them, they might miss the extra invocations in the template. Even if only one person is maintaining this code, they’re likely to make similar mistakes after a few months have passed.

    It’s much better to use the lookup functions in a Puppet manifest, assign their value to a local variable, and then reference the variable from the template. This keeps the function calls isolated in one layer of your code, where they’ll be easy to find if you need to modify them later or document them for other users.

    On May 10, 2013, at 7:19 AM, Brian Lalor wrote:
    On May 10, 2013, at 7:18 AM, Jonathan Gazeley wrote:

    ipaddr = <%= scope.function_hiera(["jrs_config_server1"]) %>
    You're passing in an array; is that intentional?

    --
    Brian Lalor
    [email protected]


    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    To post to this group, send email to [email protected].
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedMay 10, '13 at 11:18a
activeMay 13, '13 at 11:08a
posts8
users5
websitepuppetlabs.com

People

Translate

site design / logo © 2023 Grokbase