How can we satisfy goals of having all data in hiera and not modifying the module code?

42 views
Skip to first unread message

JeremyCampbell

unread,
Aug 25, 2014, 9:04:37 AM8/25/14
to puppet...@googlegroups.com
We understand that all site specific data should be in Hiera. We also understand that modules shouldn't have to be modified when they are well designed e.g. the puppetlabs/apache module. However, how do I setup apache using this module with a virtual host without putting data into the manifest. E.g to create a vhost according to the docs we need to use:

apache::vhost { 'first.example.com':
      port    
=> '80',
      docroot
=> '/var/www/first',
}

As a define it would appear that we need to use create_resources() somewhere in the module and then create a hash in hiera e.g.

apache::my_vhosts:
  host1
:
    priority
: "10"
    vhost_name
": "first.example.com"
    port"
: "80"
    docroot
": "/var/www/first"

This means that we either need to put data into the manifest (e.g. first example) or to change the module code by implementing create_resources(). So how can we satisfy both goals of having all data in hiera and not modifying the module code?

Juan Sierra Pons

unread,
Aug 25, 2014, 9:34:06 AM8/25/14
to puppet...@googlegroups.com
Hi,

You can create another abstration level and put all your specific
logic inside. Have a look to the roles & profiles literature on the
Internet.

For example create a apache profile (eg: webserver.pp) with the following:

include apache
create_resources(apache::my_vhosts,hiera_hash('apache::my_vhosts'))

This way you accomplishes the two requirements: do not touch the
module and put all your data on hiera :)

Best regards
--------------------------------------------------------------------------------------
Juan Sierra Pons ju...@elsotanillo.net
Linux User Registered: #257202
Web: http://www.elsotanillo.net Git: http://www.github.com/juasiepo
GPG key = 0xA110F4FE
Key Fingerprint = DF53 7415 0936 244E 9B00 6E66 E934 3406 A110 F4FE
--------------------------------------------------------------------------------------

Jim Ficarra

unread,
Aug 25, 2014, 9:52:21 AM8/25/14
to puppet...@googlegroups.com
You could setup setup the host-specific yaml as:
 
vhost:            “first.example.com
port:              “80”
priority:        “10”
docroot:        “/var/www/first”
 
Then your module:
 
$vhost = hiera(‘vhost’)
$port = hiera(‘port’)
$priority = hiera(‘priority’)
$docroot: = hiera(‘docroot’)
 
apache::vhost { $vhost:
      port   
=> $port,
      priority => $priority,
      docroot
=> $docroot,
}
 
This would allow you completely segregate the configuration from the data and not require modification of the module code unless something in the configuration changes.  You could use common.yaml for configuration data that applies to all hosts.
--
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/6f9aaec5-0503-488c-b70a-30887af5b353%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JeremyCampbell

unread,
Aug 25, 2014, 12:22:47 PM8/25/14
to puppet...@googlegroups.com
That makes perfect sense and achieves exactly what we need. Thank you!
Reply all
Reply to author
Forward
0 new messages