FAQ
Hello Everybody,
Can anybody please provide an example about how to
read an array using hiera in puppet 3.0.
Right now the agents are giving the following error when connecting to the
master " Could not retrieve catalog from remote server: Error 400 on
SERVER: Could not find data item users in any Hiera data file and no
default supplied ".

Following is the structure of hiera.yaml
---
:backend:
- yaml
:hierarchy:
- global
:puppet:
:datasource: data
:yaml:
# datadir is empty here, so hiera uses its defaults
# When specifying a datadir, make sure the path of the datadir exists
:datadir: /etc/puppet/hiera/data


Followin is the structure of global.yaml file:-
---
users:
- 'seventeen'
- 'eighteen'



Following is the code where am trying to use it in site.pp

$declared_users=hiera_array(users)

I am not getting, if I am missing
something obvious here or is there any problem with hiera inside puppet.


Thanks,
Nishant


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/DdS7dqv_trkJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Nishant Jain at Oct 11, 2012 at 2:45 pm
    Can anybody reply to this post.

    Thanks Nishant
    On Wednesday, October 10, 2012 4:31:26 PM UTC-4, Nishant Jain wrote:

    Hello Everybody,
    Can anybody please provide an example about how to
    read an array using hiera in puppet 3.0.
    Right now the agents are giving the following error when connecting to the
    master " Could not retrieve catalog from remote server: Error 400 on
    SERVER: Could not find data item users in any Hiera data file and no
    default supplied ".

    Following is the structure of hiera.yaml
    ---
    :backend:
    - yaml
    :hierarchy:
    - global
    :puppet:
    :datasource: data
    :yaml:
    # datadir is empty here, so hiera uses its defaults
    # When specifying a datadir, make sure the path of the datadir exists
    :datadir: /etc/puppet/hiera/data


    Followin is the structure of global.yaml file:-
    ---
    users:
    - 'seventeen'
    - 'eighteen'



    Following is the code where am trying to use it in site.pp

    $declared_users=hiera_array(users)

    I am not getting, if I am missing
    something obvious here or is there any problem with hiera inside puppet.


    Thanks,
    Nishant

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/2-LVNH421mYJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Stephen Gran at Oct 11, 2012 at 3:30 pm
    Hi,
    On Thu, 2012-10-11 at 07:45 -0700, Nishant Jain wrote:
    Can anybody reply to this post.


    Thanks Nishant

    On Wednesday, October 10, 2012 4:31:26 PM UTC-4, Nishant Jain wrote:
    Hello Everybody,
    Can anybody please provide an example
    about how to read an array using hiera in puppet 3.0.
    Right now the agents are giving the following error when
    connecting to the master " Could not retrieve catalog from
    remote server: Error 400 on SERVER: Could not find data item
    users in any Hiera data file and no default supplied ".


    Following is the structure of hiera.yaml
    ---
    :backend:
    - yaml
    :hierarchy:
    - global
    :puppet:
    :datasource: data
    :yaml:
    # datadir is empty here, so hiera uses its defaults
    # When specifying a datadir, make sure the path of the datadir
    exists
    :datadir: /etc/puppet/hiera/data




    Followin is the structure of global.yaml file:-
    ---
    users:
    - 'seventeen'
    - 'eighteen'
    Are you sure /etc/puppet/hiera/data/global.yaml exists on the puppet
    master? Why are you using :puppet: and :datasource: ?

    Cheers,
    --
    Stephen Gran
    Senior Systems Integrator - guardian.co.uk

    Please consider the environment before printing this email.
    ------------------------------------------------------------------
    Visit guardian.co.uk - newspaper of the year

    www.guardian.co.uk www.observer.co.uk www.guardiannews.com

    On your mobile, visit m.guardian.co.uk or download the Guardian
    iPhone app www.guardian.co.uk/iphone and iPad edition www.guardian.co.uk/iPad

    Save up to 37% by subscribing to the Guardian and Observer - choose the papers you want and get full digital access.
    Visit guardian.co.uk/subscribe

    ---------------------------------------------------------------------
    This e-mail and all attachments are confidential and may also
    be privileged. If you are not the named recipient, please notify
    the sender and delete the e-mail and all attachments immediately.
    Do not disclose the contents to another person. You may not use
    the information for any purpose, or store, or copy, it in any way.

    Guardian News & Media Limited is not liable for any computer
    viruses or other material transmitted with or as part of this
    e-mail. You should employ virus checking software.

    Guardian News & Media Limited

    A member of Guardian Media Group plc
    Registered Office
    PO Box 68164
    Kings Place
    90 York Way
    London
    N1P 2AP

    Registered in England Number 908396

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Nishant Jain at Oct 11, 2012 at 6:02 pm
    Yes /etc/puppet/hiera/data/global.yaml exists . I even tried removing
    :puppet and :datasource, but still its not working.
    On Thursday, October 11, 2012 11:31:03 AM UTC-4, Stephen Gran wrote:

    Hi,
    On Thu, 2012-10-11 at 07:45 -0700, Nishant Jain wrote:
    Can anybody reply to this post.


    Thanks Nishant

    On Wednesday, October 10, 2012 4:31:26 PM UTC-4, Nishant Jain wrote:
    Hello Everybody,
    Can anybody please provide an example
    about how to read an array using hiera in puppet 3.0.
    Right now the agents are giving the following error when
    connecting to the master " Could not retrieve catalog from
    remote server: Error 400 on SERVER: Could not find data item
    users in any Hiera data file and no default supplied ".


    Following is the structure of hiera.yaml
    ---
    :backend:
    - yaml
    :hierarchy:
    - global
    :puppet:
    :datasource: data
    :yaml:
    # datadir is empty here, so hiera uses its defaults
    # When specifying a datadir, make sure the path of the datadir
    exists
    :datadir: /etc/puppet/hiera/data




    Followin is the structure of global.yaml file:-
    ---
    users:
    - 'seventeen'
    - 'eighteen'
    Are you sure /etc/puppet/hiera/data/global.yaml exists on the puppet
    master? Why are you using :puppet: and :datasource: ?

    Cheers,
    --
    Stephen Gran
    Senior Systems Integrator - guardian.co.uk

    Please consider the environment before printing this email.
    ------------------------------------------------------------------
    Visit guardian.co.uk - newspaper of the year

    www.guardian.co.uk www.observer.co.uk www.guardiannews.com

    On your mobile, visit m.guardian.co.uk or download the Guardian
    iPhone app www.guardian.co.uk/iphone and iPad edition
    www.guardian.co.uk/iPad

    Save up to 37% by subscribing to the Guardian and Observer - choose the
    papers you want and get full digital access.
    Visit guardian.co.uk/subscribe

    ---------------------------------------------------------------------
    This e-mail and all attachments are confidential and may also
    be privileged. If you are not the named recipient, please notify
    the sender and delete the e-mail and all attachments immediately.
    Do not disclose the contents to another person. You may not use
    the information for any purpose, or store, or copy, it in any way.

    Guardian News & Media Limited is not liable for any computer
    viruses or other material transmitted with or as part of this
    e-mail. You should employ virus checking software.

    Guardian News & Media Limited

    A member of Guardian Media Group plc
    Registered Office
    PO Box 68164
    Kings Place
    90 York Way
    London
    N1P 2AP

    Registered in England Number 908396
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/zBdi787bfH4J.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Jcbollinger at Oct 11, 2012 at 7:03 pm

    On Thursday, October 11, 2012 11:11:07 AM UTC-5, Nishant Jain wrote:

    Yes /etc/puppet/hiera/data/global.yaml exists . I even tried removing
    :puppet and :datasource, but still its not working.
    Is that file readable by the puppetmaster? Remember that, at least in a
    typical installation, the master runs as an unprivileged user (often
    'puppet'). If file ownership and permissions, ACLs, and/or SELinux
    labeling prevent the master from reading the data file then you might get
    an error such as you report. (Look not only at the file itself, but also
    at each directory in the path to it.)


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/nGVf4N0kcTAJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Nishant Jain at Oct 11, 2012 at 7:02 pm
    Thanks Everybody, I got it working, but am still not able to read the array
    using hiera. It always read the last element of the array.
    For example in the following global.yaml file:-
    ---
    users:
    - 'seventeen'
    - 'eighteen'


    when i write hiera('users') and print it as a content it a file, It always
    write eighteen in the file, instead of seventeen , eighteen.


    It always read the last value, i.e. eighteen.

    Any idea how I can make it read the whole array.


    Thanks,
    Nishant


    On Thursday, October 11, 2012 2:32:20 PM UTC-4, jcbollinger wrote:


    On Thursday, October 11, 2012 11:11:07 AM UTC-5, Nishant Jain wrote:


    Yes /etc/puppet/hiera/data/global.yaml exists . I even tried removing
    :puppet and :datasource, but still its not working.
    Is that file readable by the puppetmaster? Remember that, at least in a
    typical installation, the master runs as an unprivileged user (often
    'puppet'). If file ownership and permissions, ACLs, and/or SELinux
    labeling prevent the master from reading the data file then you might get
    an error such as you report. (Look not only at the file itself, but also
    at each directory in the path to it.)


    John
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/dV0jz1_K9TcJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Jcbollinger at Oct 12, 2012 at 1:19 pm

    On Thursday, October 11, 2012 2:02:31 PM UTC-5, Nishant Jain wrote:
    Thanks Everybody, I got it working, but am still not able to read the
    array using hiera. It always read the last element of the array.
    For example in the following global.yaml file:-
    ---
    users:
    - 'seventeen'
    - 'eighteen'


    when i write hiera('users') and print it as a content it a file, It always
    write eighteen in the file, instead of seventeen , eighteen.


    It always read the last value, i.e. eighteen.

    Any idea how I can make it read the whole array.

    If the hiera config and data is indeed as you posted, then the problem is
    not on the reading side, but rather on the writing side. You did not show
    how you are trying to output the result, but here's one way you can test:

    $users = hiera('users')
    notify { "debug user list":
    message => inline_template('<%= @users.join(",") %>')
    }

    Look for the result in the client-side log. Note, too, that there is a
    'join' function in PuppetLabs's 'stdlib' add-in module. That would be more
    convenient to use than inline_template(), but inline_template() should work
    with Puppet straight out of the box.


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/RLmvDe63q5MJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Nishant Jain at Oct 12, 2012 at 5:51 pm
    Hello jcbollinger,
    I am actually trying to read the array into a
    variable and passsing that variable as the content of a file like below,
    file{'/tmp/nish_lat':
    ensure=>file,
    content=>hiera('users'),
    }

    My intention was to just get a way to read the array from
    a file, so that I can pass it to a define resource , where it can be used
    to create a no of resources, as there are no loops available in puppet.
    I have tried using your method of notifying, but it sends out
    an error
    Error 400 on SERVER: Failed to parse inline template:
    undefined method `join' for nil:NilClass

    I am actually new to puppet and my work as of now is to be
    able to create a no of users on a machine based on the information passed
    to it from a file.

    Thanks,
    Nishant

    On Friday, October 12, 2012 9:19:43 AM UTC-4, jcbollinger wrote:


    On Thursday, October 11, 2012 2:02:31 PM UTC-5, Nishant Jain wrote:

    Thanks Everybody, I got it working, but am still not able to read the
    array using hiera. It always read the last element of the array.
    For example in the following global.yaml file:-
    ---
    users:
    - 'seventeen'
    - 'eighteen'


    when i write hiera('users') and print it as a content it a file, It
    always write eighteen in the file, instead of seventeen , eighteen.


    It always read the last value, i.e. eighteen.

    Any idea how I can make it read the whole array.

    If the hiera config and data is indeed as you posted, then the problem is
    not on the reading side, but rather on the writing side. You did not show
    how you are trying to output the result, but here's one way you can test:

    $users = hiera('users')
    notify { "debug user list":
    message => inline_template('<%= @users.join(",") %>')
    }

    Look for the result in the client-side log. Note, too, that there is a
    'join' function in PuppetLabs's 'stdlib' add-in module. That would be more
    convenient to use than inline_template(), but inline_template() should work
    with Puppet straight out of the box.


    John
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/zudCLEGmrGcJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Jcbollinger at Oct 12, 2012 at 8:26 pm

    On Friday, October 12, 2012 9:52:01 AM UTC-5, Nishant Jain wrote:
    Hello jcbollinger,
    I am actually trying to read the array into a
    variable and passsing that variable as the content of a file like below,
    file{'/tmp/nish_lat':
    ensure=>file,
    content=>hiera('users'),
    }
    Yes, I gathered that from your earlier description. That directs Puppet to
    manage a file /tmp/nish_lat on the client, whose content is the string
    value of the object obtained by invoking hiera('users'). I inferred that
    you were doing that to check the value hiera was returning, hence I
    suggested a slightly less kludgy approach to that.


    My intention was to just get a way to read the array from
    a file, so that I can pass it to a define resource , where it can be used
    to create a no of resources, as there are no loops available in puppet.

    If you mean that was the purpose of the File resource then you going in a
    very wrong direction. Hiera itself is a way (a good one) to read an array
    from a file, as it seemed you understood.


    I have tried using your method of notifying, but it sends out
    an error
    Error 400 on SERVER: Failed to parse inline template:
    undefined method `join' for nil:NilClass

    That error message suggests that Puppet variable $users is unset or
    explicitly set to nil. Either you missed the line that sets the $users
    variable (to the value returned by "hiera('users')"), or you changed your
    data or your hiera configuration, or you ran the test in a different
    context than your earlier one.


    I am actually new to puppet and my work as of now is to be
    able to create a no of users on a machine based on the information passed
    to it from a file.

    The very simplest form of doing that in Puppet would be something like this:

    ######
    $users = hiera('users')

    user { $users: }
    ######

    That's far too simple for practical use, of course, but it demonstrates the
    basic idea of obtaining data from an external file (via hiera, in that
    case) and using it to declare possibly-multiple resources. There is also a
    variation that loads data as a hash of hashes and uses the
    create_resources() function instead of an explicit resource declaration:

    ######
    $users_hash = hiera('user_data')

    create_resources('user', $users_hash)
    ######

    Anything else is an embellishment on one of those basic themes.

    Note that managing the contents of a File resource cannot influence
    anything about other resources included in the target node's catalog. The
    catalog is compiled before any of its contents are applied (and on the
    master in a master / client setup), and that determines all the resources
    and their managed properties. I assumed you understood that, which is why
    I interpreted your File resource as a test mechanism. If you didn't know
    before then you do now.


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/604o6J7ufHgJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Nishant Jain at Oct 12, 2012 at 8:37 pm
    Thanks John,
    I actually got it working exactly using
    hiera($users) and then defining a resource and passing the array to the
    defined resource which makes it run for every element of the array.
    I guess that was again one of your post, where you have described the
    approach to perform iterations in puppet
    http://www.mail-archive.com/puppet-users@googlegroups.com/msg29238.html


    Can you please provide some good links to the tutorials where I can learn
    more about using hiera, as it looks to me like one of the major souce of
    externalizing data.


    Thanks,
    Nishant
    .
    On Friday, October 12, 2012 4:26:43 PM UTC-4, jcbollinger wrote:


    On Friday, October 12, 2012 9:52:01 AM UTC-5, Nishant Jain wrote:

    Hello jcbollinger,
    I am actually trying to read the array into a
    variable and passsing that variable as the content of a file like below,
    file{'/tmp/nish_lat':
    ensure=>file,
    content=>hiera('users'),
    }
    Yes, I gathered that from your earlier description. That directs Puppet
    to manage a file /tmp/nish_lat on the client, whose content is the string
    value of the object obtained by invoking hiera('users'). I inferred that
    you were doing that to check the value hiera was returning, hence I
    suggested a slightly less kludgy approach to that.


    My intention was to just get a way to read the array
    from a file, so that I can pass it to a define resource , where it can be
    used to create a no of resources, as there are no loops available in puppet.

    If you mean that was the purpose of the File resource then you going in a
    very wrong direction. Hiera itself is a way (a good one) to read an array
    from a file, as it seemed you understood.


    I have tried using your method of notifying, but it sends out
    an error
    Error 400 on SERVER: Failed to parse inline template:
    undefined method `join' for nil:NilClass

    That error message suggests that Puppet variable $users is unset or
    explicitly set to nil. Either you missed the line that sets the $users
    variable (to the value returned by "hiera('users')"), or you changed your
    data or your hiera configuration, or you ran the test in a different
    context than your earlier one.


    I am actually new to puppet and my work as of now is to be
    able to create a no of users on a machine based on the information passed
    to it from a file.

    The very simplest form of doing that in Puppet would be something like
    this:

    ######
    $users = hiera('users')

    user { $users: }
    ######

    That's far too simple for practical use, of course, but it demonstrates
    the basic idea of obtaining data from an external file (via hiera, in that
    case) and using it to declare possibly-multiple resources. There is also a
    variation that loads data as a hash of hashes and uses the
    create_resources() function instead of an explicit resource declaration:

    ######
    $users_hash = hiera('user_data')

    create_resources('user', $users_hash)
    ######

    Anything else is an embellishment on one of those basic themes.

    Note that managing the contents of a File resource cannot influence
    anything about other resources included in the target node's catalog. The
    catalog is compiled before any of its contents are applied (and on the
    master in a master / client setup), and that determines all the resources
    and their managed properties. I assumed you understood that, which is why
    I interpreted your File resource as a test mechanism. If you didn't know
    before then you do now.


    John
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/DR-AA5p_s0wJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Jcbollinger at Oct 15, 2012 at 2:28 pm

    On Friday, October 12, 2012 3:37:47 PM UTC-5, Nishant Jain wrote:
    Thanks John,
    I actually got it working exactly using
    hiera($users) and then defining a resource and passing the array to the
    defined resource which makes it run for every element of the array.
    I guess that was again one of your post, where you have described the
    approach to perform iterations in puppet
    http://www.mail-archive.com/puppet-users@googlegroups.com/msg29238.html


    Can you please provide some good links to the tutorials where I can learn
    more about using hiera, as it looks to me like one of the major souce of
    externalizing data.
    The product documentation is here: https://github.com/puppetlabs/hiera.

    Googling "hiera tutorial" yields lots of hits; I can't say which are the
    "good" ones.


    John

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ACOnPORz4XwJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedOct 10, '12 at 8:59p
activeOct 15, '12 at 2:28p
posts11
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase