christopher floess
2010-Jul-06 07:42 UTC
[Puppet Users] more on classes and external files
Hi, quick question: I have been following the thread: "Splitting classes into separate files" and decided to to some refactoring based on that. I have the following file structure for a module modules/packages/manifests/init.pp modules/packages/manifests/classes/redis.pp ~/puppet_config$ cat modules/packages/manifests/init.pp import "redis" ~/puppet_config$ cat modules/packages/manifests/classes/redis.pp class redis { file { "/home/adva/builds/redis_1.02-1_i386.deb": ensure => present, source => "puppet:///redis/redis_1.02-1_i386.deb"; } file { "/etc/redis.conf": ensure => present; } package { "redis": require => File["/home/adva/builds/redis_1.02-1_i386.deb"], source => "/home/adva/builds/redis_1.02-1_i386.deb", ensure => installed, provider => dpkg; } } then in manifests/modules.pp I have ~/puppet_config$ cat manifests/modules.pp # /etc/puppet/manifests/modules.pp import "base_packages" import "base_configs" import "users" import "sphinx" import "gems" import "ree" import "nginx" import "puppet_client" import "packages" puppet-admin@servercharlie:~/puppet_config$ and in manifests/nodes.pp, I have <--- snip ---> node ''ext-b2c-sk-test'' inherits default { include b2c_test include sk_base include gems_sk_all include gems_b2c_base include ree include packages::redis include nginx include sphinx adva_users{"application": username => "application",} } <--- snip ---> I''m getting the error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not parse for environment production: No file(s) found for import of ''redis'' at /home/puppet-admin/puppet_config/modules/packages/manifests/init.pp:2 So my question is, how do I change things in the 4 files above so that this runs properly. Because of the auto-load stuff mentioned in Module standards, I''ve also tried changing ''include packages::redis" to ''include redis'', but that didn''t work either. Thanks in advance, Chris -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/puppet-users?hl=en.
Michael Gliwinski
2010-Jul-06 12:03 UTC
Re: [Puppet Users] more on classes and external files
On Tuesday 06 Jul 2010 08:42:55 christopher floess wrote:> Hi, quick question: > > I have been following the thread: "Splitting classes into separate > files" and decided to to some refactoring based on that. I have the > following file structure for a module > > modules/packages/manifests/init.pp > modules/packages/manifests/classes/redis.ppmv modules/packages/manifests/classes/redis.pp modules/packages/manifests/redis.pp> > ~/puppet_config$ cat modules/packages/manifests/init.pp > import "redis"You can remove this.> ~/puppet_config$ cat modules/packages/manifests/classes/redis.pp > class redis { > file { > "/home/adva/builds/redis_1.02-1_i386.deb": > ensure => present, > source => "puppet:///redis/redis_1.02-1_i386.deb"; > } > > file { > "/etc/redis.conf": > ensure => present; > } > > package { > "redis": > require => File["/home/adva/builds/redis_1.02-1_i386.deb"], > source => "/home/adva/builds/redis_1.02-1_i386.deb", > ensure => installed, > provider => dpkg; > } > } > > then in manifests/modules.pp I have > > ~/puppet_config$ cat manifests/modules.pp > # /etc/puppet/manifests/modules.pp > > import "base_packages" > import "base_configs" > import "users" > import "sphinx" > import "gems" > import "ree" > import "nginx" > import "puppet_client" > import "packages"And ''import "packages"'' here too. Autoloader should take care of that.> puppet-admin@servercharlie:~/puppet_config$ > > and in manifests/nodes.pp, I have > <--- snip ---> > node ''ext-b2c-sk-test'' inherits default { > include b2c_test > include sk_base > include gems_sk_all > include gems_b2c_base > include ree > include packages::redisThat''s correct.> include nginx > include sphinx > adva_users{"application": username => "application",} > } > <--- snip ---> > > I''m getting the error: Could not retrieve catalog from remote server: > Error 400 on SERVER: Could not parse for environment production: No > file(s) found for import of ''redis'' at > /home/puppet-admin/puppet_config/modules/packages/manifests/init.pp:2 > > So my question is, how do I change things in the 4 files above so that > this runs properly. > > Because of the auto-load stuff mentioned in Module standards, I''ve also > tried changing ''include packages::redis" to ''include redis'', but that > didn''t work either.IIUC with autoloader you can basically think of it as: it takes class/define name requested (e.g. from include line), converts it into a filename so, e.g.: packages -> packages/manifests/init.pp packages::redis -> packages/manifests/redis.pp packages::foo::bar -> packages/manifests/foo/bar.pp and looks that up in each dir in module path.> > Thanks in advance, > Chris-- Michael Gliwinski Henderson Group Information Services 9-11 Hightown Avenue, Newtownabby, BT36 4RT Phone: 028 9034 3319 ********************************************************************************************** The information in this email is confidential and may be legally privileged. It is intended solely for the addressee and access to the email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. When addressed to our clients, any opinions or advice contained in this e-mail are subject to the terms and conditions expressed in the governing client engagement leter or contract. If you have received this email in error please notify support@henderson-group.com John Henderson (Holdings) Ltd Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, BT36 4RT. Registered in Northern Ireland Registration Number NI010588 Vat No.: 814 6399 12 ********************************************************************************* -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/puppet-users?hl=en.
On Tue, Jul 6, 2010 at 12:42 AM, christopher floess <skeptikos@gmail.com> wrote:> Hi, quick question: > > I have been following the thread: "Splitting classes into separate files" > and decided to to some refactoring based on that. I have the following file > structure for a moduleGreat, thanks for taking the time to do this. I have a few suggestions I''ll include in-line with the quoted reply. Before diving in, please keep in mind the difference between import and include. import loads a manifest and parses it, include adds a class to the catalog. The "goal" is to structure the manifests so include foo::bar automatically imports the right file without us having to manually specify an import statement.> modules/packages/manifests/init.pp > modules/packages/manifests/classes/redis.ppI recommend against the use of a "classes" directory component. Puppet and the autoloader will expect this to be a namespace underneath the module namespace, which probably isn''t what you want. For the autoloader to automatically import redis.pp above, you would have to make the statement: include packages::classes::redis "classes" is redundant since the include function only operates on classes.> ~/puppet_config$ cat modules/packages/manifests/init.pp > import "redis"init.pp should contain a single class named exactly after the module name. In your structure, init.pp should contain "class packages {}" Also, if you have import statements, it should signal something isn''t in the place puppet expects it to be.> ~/puppet_config$ cat modules/packages/manifests/classes/redis.ppI believe the ideal location for redis.pp is modules/packages/manifests/redis.pp (not in classes) and the autoloader will automatically load this file if you name the class packages::redis instead of just "redis" If you''d like to keep the classes directory component, then you could rename the class packages::classes::redis and puppet will autoload modules/packages/manifests/classes/redis.pp to look for the class.> class redis { > file { > "/home/adva/builds/redis_1.02-1_i386.deb": > ensure => present, > source => "puppet:///redis/redis_1.02-1_i386.deb"; > } > > file { > "/etc/redis.conf": > ensure => present; > } > > package { > "redis": > require => File["/home/adva/builds/redis_1.02-1_i386.deb"], > source => "/home/adva/builds/redis_1.02-1_i386.deb", > ensure => installed, > provider => dpkg; > } > } > > then in manifests/modules.pp I have > > ~/puppet_config$ cat manifests/modules.pp > # /etc/puppet/manifests/modules.pp > > import "base_packages" > import "base_configs" > import "users" > import "sphinx" > import "gems" > import "ree" > import "nginx" > import "puppet_client" > import "packages"You shouldn''t need this file at all. The expectation is that when you include a class into the catalog, puppet should automatically locate the manifest containing the class and import it for you.> puppet-admin@servercharlie:~/puppet_config$ > > and in manifests/nodes.pp, I have > <--- snip ---> > node ''ext-b2c-sk-test'' inherits default { > include b2c_test > include sk_base > include gems_sk_all > include gems_b2c_base > include ree > include packages::redis > include nginx > include sphinx > adva_users{"application": username => "application",} > } > <--- snip --->I notice you have include packages::redis. If you move redis.pp to modules/packages/manifests/redis.pp and in the file declare the class like: class packages::redis { } rather than just class redis { }> I''m getting the error: Could not retrieve catalog from remote server: Error > 400 on SERVER: Could not parse for environment production: No file(s) found > for import of ''redis'' at > /home/puppet-admin/puppet_config/modules/packages/manifests/init.pp:2This error is a result of the import redis you have. You really don''t need any import statements.> So my question is, how do I change things in the 4 files above so that this > runs properly. > > Because of the auto-load stuff mentioned in Module standards, I''ve also > tried changing ''include packages::redis" to ''include redis'', but that didn''t > work either.Puppet will import the right files if you move redis.pp into the manifests directory and name the class inside packages::redis. What puppet is doing is relatively straight forward when you say "include packages::redis" 1: import packages/manifests/init.pp 2: If no class named packages::redis results, then import packages/manifests/redis.pp if it exists. 3: If no class named packages::redis results, throw an error. Hope this helps, -- Jeff McCune puppetlabs.com -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/puppet-users?hl=en.