FAQ
Agreed, create resources is the way to create defined types using hiera
data. As a note though, if you need to create a bunch of defined types
without parameters, if, for example, you're only relying on the name
parameter, you can pass an array of titles to a declaration.
http://docs.puppetlabs.com/puppet/3/reference/lang_resources.html#array-of-titles

yaml:
---
logrotate_users:
   - alice
   - bob
   - carol

pp:
$logrotate_users = hiera_array('logrotate_users')
cron_jobs::logrotate::users { $logrotate_users: }
On Friday, August 23, 2013 10:17:05 PM UTC-7, mcd wrote:

Well normally you would use hiera_hash() and create_resources() to do it,
like this:

# yaml data source
---
cron_jobs::logrotate::users
kenweiss:
hour => 5
tomjones:
hour => 3


# pp file
---
class cron_jobs::logrotate ( $hour, $minute, $weekday ) {
...
$user_cron_options = hiera_hash('cron_jobs::logrotate::users', false)
if $user_cron_options{
create_resources('cron_jobs::logrotate::user_cron', $user_cron_options)
}
}

One thing I don't know is how to do that for defined types that do not
have any parameters. Unfortunately create_resources requires a hash for
the second argument, so you have to use hiera_hash to pull in the data, so
it has to be a hash in hiera. And I haven't figured out how to define an
empty hash yet. Or transform an array into a hash that would work for
create_resources.

/shrug

Chris


On Fri, Aug 23, 2013 at 5:01 PM, Ken Weiss <ken....@ucop.edu <javascript:>
wrote:
Hi all,

I am trying to use hiera and .yaml files to load parameters into my
declared classes. For basic classes it works great. For example:

class cron_jobs::logrotate ( $hour, $minute, $weekday ) {...

node fqdn: test.my.com

I declare the class for my node very simply:

class {'cron_jobs::logrotate': }

If I create a file in the default hiera data directory called
test.my.com.yaml and include this:

cron_jobs::logrotate::hour: 5

then sure enough, when I do a puppet apply the cron job is created to run
at 5:00 AM.


My problem is extending this to work with defined types. Let's say my
defined type looks like this when I declare it:

cron_jobs::logrotate::user_cron {'kenweiss' :}

What do I put in my .yaml file in order to get Puppet to load the
parameters automatically?

I tried a couple of things...

cron_jobs::logrotate::user_cron::kenweiss::hour 5
cron_jobs::logrotate::user_cron[kenweiss]::hour 5

Neither worked, and I can't think of any other reasonable syntax. Can
anyone point me in the right direction?

--Ken Weiss

--
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 puppet-users...@googlegroups.com <javascript:>.
To post to this group, send email to puppet...@googlegroups.com<javascript:>
.
Visit this group at http://groups.google.com/group/puppet-users.
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 puppet-users+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 7 | next ›
Discussion Overview
grouppuppet-users @
categoriespuppet
postedAug 23, '13 at 11:01p
activeAug 27, '13 at 4:50p
posts7
users5
websitepuppetlabs.com

People

Translate

site design / logo © 2021 Grokbase