Installing a package purely with Hiera configuration

3,404 views
Skip to first unread message

Brantley Hobbs

unread,
Dec 4, 2014, 4:00:34 PM12/4/14
to puppet...@googlegroups.com
Hi all!

I'm very new to puppet.  I have installed a puppet master which successfully sets the IP address and manages sudo on a couple of nodes.

I'm using Puppet 3.7 with Hiera, and so far I haven't had to write any manifest files, apart from the one that pulls in Hiera.  As far as I can tell, this is a best practice.

Now I would like to manage packages on my agents.  I assume that in the node specific Hiera file, I should be able do something like the following:

packages:
  apache2:
    ensure: installed

However, nothing gets installed.  I know I'm taking too simplistic of an approach, but I'm not sure where to start digging.  Most things I've found say that I need a "wrapper class" to read in the Hiera data and install the packages.  Is there no way to install packages purely from hiera?  I've found some modules that propose to do this, but so far I can't get them to work.  I'd like to do this without additional modules if possible; it seems like a pretty basic operation.

Thanks!
Brantley Hobbs

Andy Taylor

unread,
Dec 5, 2014, 7:55:46 AM12/5/14
to puppet...@googlegroups.com
Hiera is just a source of data - you need to have Puppet manifests/modules which interpet the data and act on it.

You can achieve installation of packages from Hiera data by using defined types and the create_resources function:

https://docs.puppetlabs.com/learning/definedtypes.html
https://docs.puppetlabs.com/references/latest/function.html#createresources

Basically you need to create a defined type which includes a package resource. Once you've done that you can use the create_resources function to pass the Hiera data to the defined type and install the packages.

The defined type would look something like this:

define hiera::packages ( $ensure ) {

  package { $title:
    ensure => $ensure
  }

}

and then the create_resources call would look like this:

$packages = hiera('packages')

create_resources(hiera::packages, $packages)

Hope that helps,

Andy

Cristian Falcas

unread,
Dec 5, 2014, 8:32:00 AM12/5/14
to puppet...@googlegroups.com
Hi,

You can use in your main manifest something like this:

hiera_include('classes', '')

This will load classes from hiera. Parameters for those classes can be
set from hiera also:

"myfirewall::block_iptables": true

Best regards,
Cristian Falcas
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/7ad3abab-32f7-42b5-9d00-01c0e8db5424%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Brantley Hobbs

unread,
Dec 5, 2014, 8:45:23 AM12/5/14
to puppet...@googlegroups.com
Since it's such a core component, I have added the type you suggested to my site.pp manifest and it works just fine.  Is there a better place for it?

Thanks for your help!

Andy Taylor

unread,
Dec 5, 2014, 9:45:19 AM12/5/14
to puppet...@googlegroups.com
That'll work fine for now, but if you throw everything into site.pp it can become difficult to manage and inflexible pretty quickly. Have a look at this part of the docs:

https://docs.puppetlabs.com/learning/modules1.html

Specifically from the "The End of One Huge Manifest" heading.

Andy

Kimo Rosenbaum

unread,
Dec 19, 2014, 3:55:03 PM12/19/14
to puppet...@googlegroups.com
Now I would like to manage packages on my agents.  I assume that in the node specific Hiera file, I should be able do something like the following:

packages:
  apache2:
    ensure: installed


<shameless plug>

I do the same thing and wrote a wrapper module to do it (I know you said you preferred to not use external modules but...):


Thanks
Kimo 
Reply all
Reply to author
Forward
0 new messages