hiera lookup

94 views
Skip to first unread message

Ugo Bellavance

unread,
May 28, 2018, 8:19:39 PM5/28/18
to Puppet Users
Hi,

I am using the postgresql module and I wanted to put all my data in hiera. Some parameters were simply looked up automatically, like postgresql::globals:: and postgresql::server::.

For postgresql::server::db, I had to put this in my manifest:

  $dbs=hiera('postgresql::server::db')
  create_resources('postgresql::server::db', $dbs)

And it works.  However, I'm looking for a way to make postgresql::server::contrib work as well, but I can't make it to work.  When I use the same recipe I get this error:

no implicit conversion of String into Hash

How can I make postgresql::server::contrib work as well and why aren't ::db and ::contrib working out-of the box like globals and server?

Format for ::db is:

postgresql::server::db { 'db1':
  user     => 'user1',
  password => password,
}

Format for ::contrib is 

class {'postgresql::server::contrib':
  package_name        => 'rh-postgresql96-postgresql-contrib',
  package_ensure      => true,
}


Thanks,

Arnau

unread,
May 29, 2018, 7:09:08 AM5/29/18
to puppet...@googlegroups.com
Hi,

are you sure the errors is about the contrib?
can you show us the hiera content for ' postgresql::server::db' ? Could it be that you have an string when a Hash is expected (for the create_resource).

Best,
Arnau

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/61c18a0f-76fe-4be8-83fc-aa8703f28cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ugo Bellavance

unread,
May 29, 2018, 9:50:57 AM5/29/18
to Puppet Users
Hi,

Here's the content of my whole file, thanks:

---

postgresql::globals::client_package_name: 'rh-postgresql96-postgresql'
postgresql::globals::createdb_path: '/opt/rh/rh-postgresql96/root/usr/bin/createdb'
postgresql::globals::datadir: '/var/opt/rh/rh-postgresql96/lib/pgsql/data'
postgresql::globals::manage_package_repo: true
postgresql::globals::needs_initdb: false
postgresql::globals::psql_path: '/opt/rh/rh-postgresql96/root/usr/bin/psql'
postgresql::globals::server_package_name: 'rh-postgresql96-postgresql-server'


postgresql::server::service_name: 'rh-postgresql96-postgresql.service'
postgresql::server::service_reload: 'systemctl reload rh-postgresql96-postgresql.service'
postgresql::server::ip_mask_deny_postgres_user: '0.0.0.0/32'
postgresql::server::ip_mask_allow_all_users: '0.0.0.0/0'
postgresql::server::listen_addresses: '*'
postgresql::server::service_restart_on_change: false

postgresql::server::contrib:
  package_name:
    'rh-postgresql96-postgresql-contrib'
  packages_ensure:
    true

postgresql::server::db:
  'mydb1':
    user:      'db1'
    password:  'db1'
  'mydb2':
    user:      'db2'
    password:  'db2'
  'mydb3':
    user:      'db3'
    password:  'db3'
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Arnau

unread,
May 29, 2018, 9:54:54 AM5/29/18
to puppet...@googlegroups.com
Hi,

postgresql::server::contrib::package_name: 'rh-postgresql96-postgresql-contrib'
postgresql::server::contrib::packages_ensure: present

HTH,
Arnau

To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/93053ac8-a9ba-46e8-a6b7-e46fa150fad8%40googlegroups.com.

Ugo Bellavance

unread,
May 29, 2018, 10:24:50 AM5/29/18
to Puppet Users


On Tuesday, May 29, 2018 at 5:54:54 AM UTC-4, Arnau wrote:
Hi,

postgresql::server::contrib::package_name: 'rh-postgresql96-postgresql-contrib'
postgresql::server::contrib::packages_ensure: present


I don't get the error anymore.  It's not doing what it's supposed but I'll look into it. I'll try the same thing with the manifest just to see.

But why do we have to use create_resources for the postgresql::server::db section but all the others are OK? Is it just because
postgresql::server::db is an array?

Thanks,

Arnau

unread,
May 29, 2018, 10:55:01 AM5/29/18
to puppet...@googlegroups.com
2018-05-29 12:24 GMT+02:00 Ugo Bellavance <ug...@lubik.ca>:


On Tuesday, May 29, 2018 at 5:54:54 AM UTC-4, Arnau wrote:
Hi,

postgresql::server::contrib::package_name: 'rh-postgresql96-postgresql-contrib'
postgresql::server::contrib::packages_ensure: present


I don't get the error anymore.  It's not doing what it's supposed but I'll look into it. I'll try the same thing with the manifest just to see.

What is it doing ?
What vesion of pupet/hiera? what version of the postgres module are you using?



But why do we have to use create_resources for the postgresql::server::db section but all the others are OK? Is it just because
postgresql::server::db is an array?


create_resources

Converts a hash into a set of resources and adds them to the catalog.

This function takes two mandatory arguments: a resource type, and a hash describing a set of resources. The hash should be in the form {title => {parameters} }:

postgresql::server::db is a define
postgresql::server::contrib is a class

In the first case you use create_resources cause you want to create resources from the type postgresql::server::db (one or many). So the create_resources function expects a hash with a list of databases + its parameters.

The second case you want to pass values to a class parameters. The class does not expect any has:

class postgresql::server::contrib (
String $package_name = $postgresql::params::contrib_package_name,
String[1] $package_ensure = 'present'
) inherits postgresql::params {

HTH,
arnau


 

Thanks,

--
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.

Ugo Bellavance

unread,
May 29, 2018, 12:25:11 PM5/29/18
to Puppet Users


On Tuesday, May 29, 2018 at 6:55:01 AM UTC-4, Arnau wrote:


2018-05-29 12:24 GMT+02:00 Ugo Bellavance <ug...@lubik.ca>:


On Tuesday, May 29, 2018 at 5:54:54 AM UTC-4, Arnau wrote:
Hi,

postgresql::server::contrib::package_name: 'rh-postgresql96-postgresql-contrib'
postgresql::server::contrib::packages_ensure: present


I don't get the error anymore.  It's not doing what it's supposed but I'll look into it. I'll try the same thing with the manifest just to see.

What is it doing ?

It should be install the package with the name specified in postgresql::server::contrib::package_name

Setting the parameters in the manifest works:

class {'postgresql::server::contrib':
  package_name        => 'rh-postgresql96-postgresql-contrib',
  package_ensure      => 'present',
}

But this hiera data doesn't:

postgresql::server::contrib::package_name: 'rh-postgresql96-postgresql-contrib'
postgresql::server::contrib::packages_ensure: present

What vesion of pupet/hiera? what version of the postgres module are you using?

# puppet -V
4.10.10

# hiera -V
1.3.4

puppetlabs-postgresql (v5.3.0)

I ran puppet in debug mode and when I use the manifest, I can see all the entries related to Package[postgresql-contrib], but nothing when using hiera.
 



But why do we have to use create_resources for the postgresql::server::db section but all the others are OK? Is it just because
postgresql::server::db is an array?


create_resources

Converts a hash into a set of resources and adds them to the catalog.

This function takes two mandatory arguments: a resource type, and a hash describing a set of resources. The hash should be in the form {title => {parameters} }:

postgresql::server::db is a define
postgresql::server::contrib is a class

In the first case you use create_resources cause you want to create resources from the type postgresql::server::db (one or many). So the create_resources function expects a hash with a list of databases + its parameters.

The second case you want to pass values to a class parameters. The class does not expect any has:

class postgresql::server::contrib (
String $package_name = $postgresql::params::contrib_package_name,
String[1] $package_ensure = 'present'
) inherits postgresql::params {

So class parameters are automatically looked up in hiera, but define parameters (or whatever name it is for objects) is not?

jcbollinger

unread,
May 29, 2018, 3:50:22 PM5/29/18
to Puppet Users


On Tuesday, May 29, 2018 at 7:25:11 AM UTC-5, Ugo Bellavance wrote:


On Tuesday, May 29, 2018 at 6:55:01 AM UTC-4, Arnau wrote:


2018-05-29 12:24 GMT+02:00 Ugo Bellavance <ug...@lubik.ca>:


On Tuesday, May 29, 2018 at 5:54:54 AM UTC-4, Arnau wrote:
Hi,

postgresql::server::contrib::package_name: 'rh-postgresql96-postgresql-contrib'
postgresql::server::contrib::packages_ensure: present


I don't get the error anymore.  It's not doing what it's supposed but I'll look into it. I'll try the same thing with the manifest just to see.

What is it doing ?

It should be install the package with the name specified in postgresql::server::contrib::package_name

Setting the parameters in the manifest works:

class {'postgresql::server::contrib':
  package_name        => 'rh-postgresql96-postgresql-contrib',
  package_ensure      => 'present',
}

But this hiera data doesn't:

postgresql::server::contrib::package_name: 'rh-postgresql96-postgresql-contrib'
postgresql::server::contrib::packages_ensure: present


That's awfully surprising if those data appear in an Hiera data file from which you are successfully loading other data.  If that is in fact happening then the most likely reason would be that a resource-like class declaration for that class somewhere in your manifest set is explicitly declaring different parameter values for that class (in which case the Hiera data will not be consulted).  But if that were the case, then I would expect Puppet to raise an error when you added your own resource-like declaration of the same class.  Another possibility is that there are conflicting data in some higher-priority level of your data hierarchy, but that would be surprising considering how you arrived where you now are.

My best guess, therefore, is that the file in which you placed the parameter data is not being consulted at all for the node in question (so that in fact you are not successfully loading other data from it, either).

 
So class parameters are automatically looked up in hiera, but define parameters (or whatever name it is for objects) is not?


That is correct.  There are good reasons for it, but a discussion of those would be tangential.  If you're interested, you can find at least one such discussion in the archives of this group.


John

Ugo Bellavance

unread,
May 29, 2018, 6:04:10 PM5/29/18
to Puppet Users
That's awfully surprising if those data appear in an Hiera data file from which you are successfully loading other data.  If that is in fact happening then the most likely reason would be that a resource-like class declaration for that class somewhere in your manifest set is explicitly declaring different parameter values for that class (in which case the Hiera data will not be consulted).  But if that were the case, then I would expect Puppet to raise an error when you added your own resource-like declaration of the same class.  Another possibility is that there are conflicting data in some higher-priority level of your data hierarchy, but that would be surprising considering how you arrived where you now are.

My best guess, therefore, is that the file in which you placed the parameter data is not being consulted at all for the node in question (so that in fact you are not successfully loading other data from it, either).


I'm testing with a minimal setup, just to make sure.

I have one manifest, site.pp, that I call locally (no server), and one hiera file, common.yaml.

I found it.  I stupidly commented the whole class declaration in site.pp.

When I leave just the class declaration it works:

class {'postgresql::server::contrib':
}


Is there a way to have the class declaration in hiera? I tried using this at the top of my yaml file but it didn't work:

---
classes:
  - postgresql::server::contrib
 
 
So class parameters are automatically looked up in hiera, but define parameters (or whatever name it is for objects) is not?


That is correct.  There are good reasons for it, but a discussion of those would be tangential.  If you're interested, you can find at least one such discussion in the archives of this group.

 
Ok thanks,

Are the modules supposed to manage that or the user? 

Thanks,

jcbollinger

unread,
May 30, 2018, 1:06:31 PM5/30/18
to Puppet Users


On Tuesday, May 29, 2018 at 1:04:10 PM UTC-5, Ugo Bellavance wrote:
That's awfully surprising if those data appear in an Hiera data file from which you are successfully loading other data.  If that is in fact happening then the most likely reason would be that a resource-like class declaration for that class somewhere in your manifest set is explicitly declaring different parameter values for that class (in which case the Hiera data will not be consulted).  But if that were the case, then I would expect Puppet to raise an error when you added your own resource-like declaration of the same class.  Another possibility is that there are conflicting data in some higher-priority level of your data hierarchy, but that would be surprising considering how you arrived where you now are.

My best guess, therefore, is that the file in which you placed the parameter data is not being consulted at all for the node in question (so that in fact you are not successfully loading other data from it, either).


I'm testing with a minimal setup, just to make sure.

I have one manifest, site.pp, that I call locally (no server), and one hiera file, common.yaml.

I found it.  I stupidly commented the whole class declaration in site.pp.

When I leave just the class declaration it works:

class {'postgresql::server::contrib':
}


Well if that serves your needs (and it should) then it is better form to use an include-like declaration instead:

include 'postgresql::server::contrib'

But that's mostly a style consideration.  It will affect behavior only if now or in the future there is a(nother) resource-like declaration of that class somewhere in your manifest set.



Is there a way to have the class declaration in hiera? I tried using this at the top of my yaml file but it didn't work:

---
classes:
  - postgresql::server::contrib


Hiera just provides data and metadata.  It does not have any inherent behavior associated.

But that absolutely can have the form of an array of class names, which can even be spread across multiple hierarchy levels, and you can use that array to declare the named classes.  The old way was to use the hiera_include() function in one of your manifests, but in recent Puppet (4.x and later) you should be using the lookup() function and regular include() function:

include(lookup('classes', Array[String], 'unique', []))

 
 
 
So class parameters are automatically looked up in hiera, but define parameters (or whatever name it is for objects) is not?


That is correct.  There are good reasons for it, but a discussion of those would be tangential.  If you're interested, you can find at least one such discussion in the archives of this group.

 
Ok thanks,

Are the modules supposed to manage that or the user? 


Whoever declares a resource instance or a class is responsible for binding the appropriate values to its parameters.  In particular, modules are responsible for binding appropriate data to the resources and classes that they declare internally, but you are responsible for binding values to the resources and classes that you declare, regardless of where the class or resource type is defined, and, for resources, regardless of whether they are of plug-in or defined type.  If one interprets "the user" as "whoever is responsible for the declaration" on an entity-by-entity basis, then that simplifies to the user being responsible for managing parameters.

Of course, where a resource type or class defines default values for its parameters and those values meet your requirements, it's fine to rely on those.  You don't necessarily need to explicitly provide a value for every parameter.  And do note the important distinction between declaring a class or resource, and defining a class or resource type.


John

Ugo Bellavance

unread,
May 30, 2018, 4:01:40 PM5/30/18
to Puppet Users
When I leave just the class declaration it works:

class {'postgresql::server::contrib':
}


Well if that serves your needs (and it should) then it is better form to use an include-like declaration instead:

include 'postgresql::server::contrib'

But that's mostly a style consideration.  It will affect behavior only if now or in the future there is a(nother) resource-like declaration of that class somewhere in your manifest set.


Excellent.
 

Is there a way to have the class declaration in hiera? I tried using this at the top of my yaml file but it didn't work:

---
classes:
  - postgresql::server::contrib


Hiera just provides data and metadata.  It does not have any inherent behavior associated.

But that absolutely can have the form of an array of class names, which can even be spread across multiple hierarchy levels, and you can use that array to declare the named classes.  The old way was to use the hiera_include() function in one of your manifests, but in recent Puppet (4.x and later) you should be using the lookup() function and regular include() function:

include(lookup('classes', Array[String], 'unique', []))

 
 
 
So class parameters are automatically looked up in hiera, but define parameters (or whatever name it is for objects) is not?


That is correct.  There are good reasons for it, but a discussion of those would be tangential.  If you're interested, you can find at least one such discussion in the archives of this group.

 
Ok thanks,

Are the modules supposed to manage that or the user? 


Whoever declares a resource instance or a class is responsible for binding the appropriate values to its parameters.  In particular, modules are responsible for binding appropriate data to the resources and classes that they declare internally, but you are responsible for binding values to the resources and classes that you declare, regardless of where the class or resource type is defined, and, for resources, regardless of whether they are of plug-in or defined type.  If one interprets "the user" as "whoever is responsible for the declaration" on an entity-by-entity basis, then that simplifies to the user being responsible for managing parameters.

I see.  During my testing I found out that if I use create_resources and put nothing about it, it throws an error.
 

Of course, where a resource type or class defines default values for its parameters and those values meet your requirements, it's fine to rely on those.  You don't necessarily need to explicitly provide a value for every parameter.  And do note the important distinction between declaring a class or resource, and defining a class or resource type.

This is something that I have always had trouble understanding and lacked time to read more on it.  And even if I read on it...
 


John


Thanks John.  You and Arnau are simply amazing. I say something similar almost every time I post on this group, but this group provide better support than any of our software/hardware vendors. Faster support, and of better quality. Kudos to all the people who participate here.

jcbollinger

unread,
May 31, 2018, 12:53:28 PM5/31/18
to Puppet Users


On Wednesday, May 30, 2018 at 11:01:40 AM UTC-5, Ugo Bellavance wrote:
 
 

Of course, where a resource type or class defines default values for its parameters and those values meet your requirements, it's fine to rely on those.  You don't necessarily need to explicitly provide a value for every parameter.  And do note the important distinction between declaring a class or resource, and defining a class or resource type.

This is something that I have always had trouble understanding and lacked time to read more on it.  And even if I read on it...


The distinction is analogous to that between defining a function and calling one.  "Defining" says what the class or type name means:

# Class definition
class mymodule::myclass (String $a_param) {
  notify
{ "${a_param}": }
}

or

# (Defined) type definition
define mymodule
::mytype (String $a_param) {
  notify
{ "${title}: ${a_param}": }
}

"Declaring" says to actually use the entity:

# A resource-like class declaration
class { 'mymodule::myclass': a_param => 'value' }

# Various include-like class declarations:
include
'mymodule::myclass'
require 'mymodule::myclass'
contain
'mymodule::myclass'

# A resource declaration
mymodule
::mytype { 'title': a_param => 'value' }

# A function call that causes a resource to be declared
create_resources
('mymodule::mytype', { 'title2' => { 'a_param' => 'value2' } })


John
Reply all
Reply to author
Forward
0 new messages