Moving config to an ENC

507 views
Skip to first unread message

Justin Lambert

unread,
Jul 5, 2011, 4:40:59 PM7/5/11
to puppet...@googlegroups.com
I have recently started moving the config of our puppet hosts out of the nodes files and into an ENC so they can be managed through a web UI by someone with less technical experience without the fear of a typo causing a failure of all catalogs to compile.  As a result, I have been looking at which modules need to be rewritten to support this.  The problem I have run into is, how do you do something such as add multiple virtual hosts using the YAML output of an ENC? 

I currently have something like:

  apache::virtualhost { 'site1': location => '/hosted/site1', url => 'http://site1.com' }
  apache::virtualhost { 'site2': location => '/hosted/site2', url => 'http://site2.com' }
}

This uses 'define apache::virtualhost' in order to create multiple sites, works fine.  The YAML from an ENC (referencing http://docs.puppetlabs.com/guides/external_nodes.html) doesn't look to support this kind of definition so I need to find an alternative.  My next thought was that I can pass parameters to a parameterized class.  No love there as you can't instantiate a class multiple times with different parameters.  How are others solving this issue?

Thanks,
jl

Dan Bode

unread,
Jul 6, 2011, 12:42:16 AM7/6/11
to puppet...@googlegroups.com
Hi J,

The create resources function was created to serve this exact use case (the README actually mentions your exact use case :) )

https://github.com/puppetlabs/puppetlabs-create_resources

This will require 2.6.5 or higher to work (That is the first version where ENC's support param classes)

The function was also merged into core in 2.7.0

-Dan

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

Justin Lambert

unread,
Jul 6, 2011, 9:22:19 AM7/6/11
to puppet...@googlegroups.com
This looks exactly like what I was looking for, thank you.  This might be worth mentioning on the ENC page so people like myself can find it easier.

Justin Lambert

unread,
Jul 12, 2011, 1:43:49 PM7/12/11
to puppet...@googlegroups.com
I have just gotten to playing with this and am doing something wrong, probably very basic.

On the puppetmaster (which for my testing is also the client) I have create_resources.rb in /var/lib/puppet/lib/puppet/parser/functions.

I wrote a new ENC that will just output a very basic YAML to test this, the output is:
classes:
 yumreposerver:
  yumreposerver::locations:
   centos5:
    distro: centos
    version: 5.6

In my modules directory I have yumreposerver/manifests/locations.pp:
class yumreposerver::locations ( $instances = {} )
{
  create_resources('yumreposerver::location', $instances)
}

yumreposerver/manifests/location.pp:
define yumreposerver::location( $distro, $version ) {
.....
}

puppet agent -t --noop returns:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter yumreposerver::locations on node <name>

 Puppet version 2.6.9 on SL6.

Any insight as to where I have gone wrong?

Thanks,
jl

Denmat

unread,
Jul 12, 2011, 4:33:18 PM7/12/11
to puppet...@googlegroups.com
Hi, is 'something::other' valid in yaml?
Cheers
Den

Justin Lambert

unread,
Jul 12, 2011, 5:59:51 PM7/12/11
to puppet...@googlegroups.com
I am using the create_resource module backported from 2.7 to 2.6 to make this possible.  The module I am using was recommeded by Dan Bode and can be found at https://github.com/puppetlabs/puppetlabs-create_resources.

I'm sure it is just something in the way I am implementing it.

Dan Bode

unread,
Jul 13, 2011, 1:35:32 AM7/13/11
to puppet...@googlegroups.com
On Tue, Jul 12, 2011 at 10:43 AM, Justin Lambert <jlam...@localmatters.com> wrote:
I have just gotten to playing with this and am doing something wrong, probably very basic.

On the puppetmaster (which for my testing is also the client) I have create_resources.rb in /var/lib/puppet/lib/puppet/parser/functions.

I wrote a new ENC that will just output a very basic YAML to test this, the output is:
classes:
 yumreposerver:
  yumreposerver::locations:
 
   centos5:
    distro: centos
    version: 5.6

it should be something like:

yumreposerver:
  instances:
    centos5:
      distro:
...

there is no yumreposerver parameter in the yum server class, only an instances parameter
 

In my modules directory I have yumreposerver/manifests/locations.pp:
class yumreposerver::locations ( $instances = {} )
{
  create_resources('yumreposerver::location', $instances)
}

yumreposerver/manifests/location.pp:
define yumreposerver::location( $distro, $version ) {
.....
}

puppet agent -t --noop returns:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter yumreposerver::locations on node <name>

I agree that this is not a very clear error message, can you run with --trace?

 

Justin Lambert

unread,
Jul 13, 2011, 11:56:28 AM7/13/11
to puppet...@googlegroups.com
Thanks for the response Dan, that was an easy fix. 


Here is a trace:
# puppet agent -t --trace
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/rest.rb:56:in `deserialize'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/rest.rb:75:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/indirection.rb:188:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector.rb:50:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:240:in `retrieve_new_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:429:in `thinmark'
/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:428:in `thinmark'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:239:in `retrieve_new_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:86:in `retrieve_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:111:in `retrieve_and_apply_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:150:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:39:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent/locker.rb:21:in `lock'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:39:in `run'
/usr/lib/ruby/1.8/sync.rb:230:in `synchronize'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:39:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:103:in `with_client'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:37:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:172:in `call'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:172:in `controlled_run'
/usr/lib/ruby/site_ruby/1.8/puppet/agent.rb:35:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application/agent.rb:114:in `onetime'
/usr/lib/ruby/site_ruby/1.8/puppet/application/agent.rb:88:in `run_command'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:305:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:420:in `hook'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:305:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:411:in `exit_on_fail'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:305:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/util/command_line.rb:62:in `execute'
/usr/bin/puppet:4
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter yumreposerver::locations on node kinks.corp.localmatters.com
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
Reply all
Reply to author
Forward
0 new messages