[Puppet Users] Re: erb template and variable check

2010-12-19 Thread Nicolas Aizier
Oh yeah sorry I forgot the line concerning the variable.

the template contain also this line :
***
server  <%= ntpserver %>
***

No big deal but it seems to pose a problem during the first run. And I
really don't understand why.


On Dec 20, 2:14 pm, Patrick  wrote:
> On Dec 19, 2010, at 8:03 PM, Nicolas Aizier wrote:
>
>
>
>
>
>
>
>
>
> > Hi everyone,
>
> > I'm actually working on implementing templates as it is a very
> > convenient and powerfull way to configure files properly. But I'm
> > actually meeting a little problem, not a blocking one but a strange
> > thing.
>
> > Basically my module is configuring the ntp client, no big deal.
> > manifest/init.pp of the module define a simple variable from facts to
> > know if it's a VM or not
>
> > code :
> > ***
>
> > $HardwareType = $manufacturer ? { 'VMware, Inc.' => 'VM', default =>
> > 'PHYSICAL' }
> > $ntpserver = 'time.au.fcl.internal'
>
> > class ntp
> > {
> >    package { 'ntp':
> >    ensure          => present,
> >    }
>
> >    file { '/etc/ntp.conf':
> >    owner           => root,
> >    group           => root,
> >    mode            => 644,
> >    content         => template('/etc/puppet/modules/ntp/templates/
> > ntp.conf.erb'),
> >    notify          => Service['ntpd'],
> >    require         => Package['ntp'],
> >    }
>
> >    service { 'ntpd':
> >    ensure          => running,
> >    enable          => true,
> >    hasrestart      => true,
> >    require         => Package['ntp'],
> >    }
> > }
> > ***
>
> > and template from the same module check if it's a VM or not and add a
> > special parameter to the ntp.conf if it is.
>
> > extract from the code :
> > ***
> > <% if @HardwareType == "VM" %>
> > # VMWare Option:
> > # Instructs NTP not to give up if it sees a large jump in time.
> > # This is important for coping with large time drifts and resuming
> > virtual machines from their suspended state.
> > tinker panic 0
> > <% end %>
> > ***
>
> > My problem is that on the first run I got a nice error like :
> > ***
> > [r...@foo puppet]# puppet agent --test
> > notice: Ignoring --listen on onetime run
> > err: Could not retrieve catalog from remote server: Error 400 on
> > SERVER: Failed to parse template /etc/puppet/modules/ntp/templates/
> > ntp.conf.erb: Could not find value for 'ntpserver' at /etc/puppet/
> > modules/ntp/manifests/init.pp:25 on node foo.fqdn
> > warning: Not using cache on failed catalog
> > err: Could not retrieve catalog; skipping run
> > ***
>
> > Second run is fine even if run directly after the first one  
> > /etc/puppet/modules/ntp/manifests/init.pp:25 is the "content template"
> > line. So it seems that puppet didn't manage to get the variable on the
> > first run but the second run is ok. Strange isn't it ? Any hint ?
>
> Does the template use the $ntpserver line?  Right now something's not making 
> sense and I'd guess it's because something is left out.

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



Re: [Puppet Users] Re: Referencing the same package from multiple classes

2010-12-19 Thread Patrick

On Dec 19, 2010, at 1:37 AM, Ken Barber wrote:

> Would be terrible - because I would lose the arguments if the package was 
> defined elsewhere earlier. That would be dumb. Also - the reverse is true ... 
> by defining your own package you may be ruining someone else's package 
> definition which defines arguments. Like you say - the ordering can cause 
> problems.
> 
> FYI - The use-case where I would use the if !defined methodology would be 
> when you are defining a re-usable module that you know may (but not always) 
> conflict with another. Nothing is a silver bullet it seems in puppet, and I 
> have had to use this method at least once or twice to avoid stepping on 
> pre-existing content that I can't influence :-).

Ya.  This is what I meant.  Thanks for explaining.  For the original example, 
it's just easier to create a tomcat class that has the packages and then 
include the tomcat class in both service classes.

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



Re: [Puppet Users] erb template and variable check

2010-12-19 Thread Patrick

On Dec 19, 2010, at 8:03 PM, Nicolas Aizier wrote:

> Hi everyone,
> 
> I'm actually working on implementing templates as it is a very
> convenient and powerfull way to configure files properly. But I'm
> actually meeting a little problem, not a blocking one but a strange
> thing.
> 
> Basically my module is configuring the ntp client, no big deal.
> manifest/init.pp of the module define a simple variable from facts to
> know if it's a VM or not
> 
> code :
> ***
> 
> $HardwareType = $manufacturer ? { 'VMware, Inc.' => 'VM', default =>
> 'PHYSICAL' }
> $ntpserver = 'time.au.fcl.internal'
> 
> class ntp
> {
>   package { 'ntp':
>   ensure  => present,
>   }
> 
>   file { '/etc/ntp.conf':
>   owner   => root,
>   group   => root,
>   mode=> 644,
>   content => template('/etc/puppet/modules/ntp/templates/
> ntp.conf.erb'),
>   notify  => Service['ntpd'],
>   require => Package['ntp'],
>   }
> 
>   service { 'ntpd':
>   ensure  => running,
>   enable  => true,
>   hasrestart  => true,
>   require => Package['ntp'],
>   }
> }
> ***
> 
> and template from the same module check if it's a VM or not and add a
> special parameter to the ntp.conf if it is.
> 
> extract from the code :
> ***
> <% if @HardwareType == "VM" %>
> # VMWare Option:
> # Instructs NTP not to give up if it sees a large jump in time.
> # This is important for coping with large time drifts and resuming
> virtual machines from their suspended state.
> tinker panic 0
> <% end %>
> ***
> 
> My problem is that on the first run I got a nice error like :
> ***
> [r...@foo puppet]# puppet agent --test
> notice: Ignoring --listen on onetime run
> err: Could not retrieve catalog from remote server: Error 400 on
> SERVER: Failed to parse template /etc/puppet/modules/ntp/templates/
> ntp.conf.erb: Could not find value for 'ntpserver' at /etc/puppet/
> modules/ntp/manifests/init.pp:25 on node foo.fqdn
> warning: Not using cache on failed catalog
> err: Could not retrieve catalog; skipping run
> ***
> 
> Second run is fine even if run directly after the first one  
> /etc/puppet/modules/ntp/manifests/init.pp:25 is the "content template"
> line. So it seems that puppet didn't manage to get the variable on the
> first run but the second run is ok. Strange isn't it ? Any hint ?

Does the template use the $ntpserver line?  Right now something's not making 
sense and I'd guess it's because something is left out.

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



[Puppet Users] erb template and variable check

2010-12-19 Thread Nicolas Aizier
Hi everyone,

I'm actually working on implementing templates as it is a very
convenient and powerfull way to configure files properly. But I'm
actually meeting a little problem, not a blocking one but a strange
thing.

Basically my module is configuring the ntp client, no big deal.
manifest/init.pp of the module define a simple variable from facts to
know if it's a VM or not

code :
***

$HardwareType = $manufacturer ? { 'VMware, Inc.' => 'VM', default =>
'PHYSICAL' }
$ntpserver = 'time.au.fcl.internal'

class ntp
{
package { 'ntp':
ensure  => present,
}

file { '/etc/ntp.conf':
owner   => root,
group   => root,
mode=> 644,
content => template('/etc/puppet/modules/ntp/templates/
ntp.conf.erb'),
notify  => Service['ntpd'],
require => Package['ntp'],
}

service { 'ntpd':
ensure  => running,
enable  => true,
hasrestart  => true,
require => Package['ntp'],
}
}
***

and template from the same module check if it's a VM or not and add a
special parameter to the ntp.conf if it is.

extract from the code :
***
<% if @HardwareType == "VM" %>
# VMWare Option:
# Instructs NTP not to give up if it sees a large jump in time.
# This is important for coping with large time drifts and resuming
virtual machines from their suspended state.
tinker panic 0
<% end %>
***

My problem is that on the first run I got a nice error like :
***
[r...@foo puppet]# puppet agent --test
notice: Ignoring --listen on onetime run
err: Could not retrieve catalog from remote server: Error 400 on
SERVER: Failed to parse template /etc/puppet/modules/ntp/templates/
ntp.conf.erb: Could not find value for 'ntpserver' at /etc/puppet/
modules/ntp/manifests/init.pp:25 on node foo.fqdn
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
***

Second run is fine even if run directly after the first one  
/etc/puppet/modules/ntp/manifests/init.pp:25 is the "content template"
line. So it seems that puppet didn't manage to get the variable on the
first run but the second run is ok. Strange isn't it ? Any hint ?

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



Re: [Puppet Users] Serving files while ignoring some (e.g. .svn)

2010-12-19 Thread Stefan Schulte
On Sun, Dec 19, 2010 at 03:13:05PM -0800, Don Jackson wrote:
> 
> I make user of the puppet fileserving capability to serve up configs and 
> smaller executables I need on my deployed servers.
> 
> Sometimes I populate directories to be served on the puppetmaster via 
> subversion.
> 
> When I recursively populate this kind of directory via puppet, it brings over 
> the .svn directory, etc, which is not what I want.
> 
> How can I configure either the puppet file server, or modify my manifest, to 
> prevent pulling over the .svn directory also?

the fileresource has an ignore paramter for this. Have a look at the
type reference:
http://docs.puppetlabs.com/references/stable/type.html#ignore

-Stefan


pgp7cZR8QGtbZ.pgp
Description: PGP signature


[Puppet Users] Serving files while ignoring some (e.g. .svn)

2010-12-19 Thread Don Jackson

I make user of the puppet fileserving capability to serve up configs and 
smaller executables I need on my deployed servers.

Sometimes I populate directories to be served on the puppetmaster via 
subversion.

When I recursively populate this kind of directory via puppet, it brings over 
the .svn directory, etc, which is not what I want.

How can I configure either the puppet file server, or modify my manifest, to 
prevent pulling over the .svn directory also?


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



Re: [Puppet Users] Update time in template file.

2010-12-19 Thread Stefan Schulte
Hi

On Sun, Dec 19, 2010 at 01:16:34PM -0800, rjl wrote:
> Hi all,
> How can I put in an update time in a template file? The problem I am
> running it to is this...
> 
> Here is my file to update the timestamp
> 
> snmp.conf.erb
> 
> # HEADER: [ <%= Time.now.gmtime %> ] Modified by puppet.
> defVersion 2c
> devCommunity somecommunity
> 
> 
> The problem is that everytime puppet runs, it updates the time stamp.
> I only want it to update if there was an actual change to the content
> of the file

And how whould puppet know what you consider "an actual change". You
specified that the actual systemtime should be in the first line. Since
it's not true on your client, puppet will change the file (cause
checksums are different).

Or to put it this way: Imagine puppet distributed the file with an actual
timestamp. Someone now opens the file and change the timestamp in your
header. What do you expect puppet to do now?

If you really depend on your headerline consider the following: Don't
use Time.now but use something like
File.stat('/etc/puppet/modules/snmp/template/snmp.conf.erb').mtime.gmtime
[Maybe theres a way to address the filename from the template itself,
but I havent figured that out; __FILE__ and ARGV are not working]

This will be the same in every puppet run (except you changed the
template). But if you assign your class to a new node, the header will
still reflact the time when you changed the file on your master, and not
when puppet installed that file on your node.

-Stefan


pgptMKzDFI9Py.pgp
Description: PGP signature


Re: [Puppet Users] Update time in template file.

2010-12-19 Thread Daniel Pittman
On Mon, Dec 20, 2010 at 08:16, rjl  wrote:

> How can I put in an update time in a template file? The problem I am
> running it to is this...  Here is my file to update the timestamp

[...]

> The problem is that everytime puppet runs, it updates the time stamp.
> I only want it to update if there was an actual change to the content
> of the file

It would: there is no way for puppet to know that the changed content
of the template header is "unimportant", compared to other changes.
(Given this is an ERB template, there is no possible way to ever
determine that, unfortunately, and we can't hook template generation
well enough either.)

Your only solution would be to use some detail that did not ever
change: personally, I used the "Time Stamp" feature that Emacs offers
to statically update the timestamp when the file was saved, rather
than puppet.

If you wanted something more automatic I would probably look to VCS
keyword expansion, or to using the mtime of the template on the server
as the date, rather than the time that puppet expanded it.

Regards,
Daniel
-- 
✣ Daniel Pittman            ✉ dan...@rimspace.net            ☎ +61 401 155 707
              ♽ made with 100 percent post-consumer electrons

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



Re: [Puppet Users] Appending to Variables in a global context

2010-12-19 Thread Daniel Pittman
On Mon, Dec 20, 2010 at 01:34, Spenser Gilliland  wrote:

> That's still ugly but I see how it works.  I think I'll give it a shot
> that way see how it goes
>
> I still need to do something to make sure that the class is
> instantiated after the tables are instantited.
>
> Run stages maybe? Uhh, still ugly.  I wish there was just some kind of
> syntactical element for this.

For that, file a feature request bug report. :)  FWIW, I think this
overlaps with a similar problem that I faced, and which we used the
'concat' system to work around.  Having a standard puppet solution
would be good.

Regards,
Daniel
-- 
✣ Daniel Pittman            ✉ dan...@rimspace.net            ☎ +61 401 155 707
              ♽ made with 100 percent post-consumer electrons

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



[Puppet Users] Update time in template file.

2010-12-19 Thread rjl
Hi all,
How can I put in an update time in a template file? The problem I am
running it to is this...

Here is my file to update the timestamp

snmp.conf.erb

# HEADER: [ <%= Time.now.gmtime %> ] Modified by puppet.
defVersion 2c
devCommunity somecommunity


The problem is that everytime puppet runs, it updates the time stamp.
I only want it to update if there was an actual change to the content
of the file

Thanks in advace.

rjl

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



Re: [Puppet Users] variables with no value

2010-12-19 Thread Arnau Bria
On Sun, 19 Dec 2010 16:57:06 +0100
Stefan Schulte wrote:

> On Fri, Dec 10, 2010 at 11:31:18AM +0100, Arnau Bria wrote:
> > Hi all,
Hi,

> > When I run the client in nodeb, and add a notify of root_password,
> > I see that nodeb's root_password has a value and it's serviceA!?!?
> 
> This can happen when you have set the var in top scope (nodes.pp
> directly or in site.pp) or you have some missing bracket somewhere and
> your nodedefinition still works magically while scope is totally
> mixed up (happened to me a few times)
that was what happened. Someone defined it at node's top, and it
became a "global" defined var.
 
> -Stefan
Arnau

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



Re: [Puppet Users] variables with no value

2010-12-19 Thread Stefan Schulte
On Fri, Dec 10, 2010 at 11:31:18AM +0100, Arnau Bria wrote:
> Hi all,
> 
> We'd like to share a class, and do something like:
> 
> class common_defaults {
> [...]
>  user { 'root':
>ensure  => present,
>password=> $root_password ? {
>   'serviceA'=> 'passwdA',
>   default   => 'passwdB',
>  },
> [...]
> }
> 
> $root_passwd  only has value if someone has defined it. So, i.e:
> 
> nodes.pp 
> nodea {
>   $root_passwd=serviceA
>   include common_defaults
> }
> 
> nodeb {
>   include common_defaults
> }
> 

Maybe its just a typo in your mail, but you set $root_passwd and test
$root_password.

> When I run the client in nodeb, and add a notify of root_password, I see
> that nodeb's root_password has a value and it's serviceA!?!?

This can happen when you have set the var in top scope (nodes.pp
directly or in site.pp) or you have some missing bracket somewhere and
your nodedefinition still works magically while scope is totally mixed up
(happened to me a few times)

-Stefan


pgpO3eYLkW4Qd.pgp
Description: PGP signature


Re: [Puppet Users] Appending to Variables in a global context

2010-12-19 Thread Spenser Gilliland
That's still ugly but I see how it works.  I think I'll give it a shot
that way see how it goes

I still need to do something to make sure that the class is
instantiated after the tables are instantited.

Run stages maybe? Uhh, still ugly.  I wish there was just some kind of
syntactical element for this.

Spenser

On Sun, Dec 19, 2010 at 6:17 AM, Matthew Macdonald-Wallace
 wrote:
> On Sun, 2010-12-19 at 04:40 -0600, Spenser Gilliland wrote:
>> Matthew,
>>
>> I'm a bit confused on your code,  how does an instance get added to the db?
>
> Yeah, that's probably my fault... :D
>
> My thought was that if you have a known path to the redmine instances
> you could create a ruby class which iterates over the filesystem and
> pulls each directory/installation name into a CSV string.
>
> If you prefix your redmine database names with something obvious when
> you install them, then you should be able to connect to the database
> server and extract the table names that are relevant using "use
> mysql;SELECT tableName from tables where tableName LIKE '%redmine_prefix
> %';" or similar.
>
> So the "db" which I spoke of is more of a datastore/list which contains
> the currently installed redmine instances - how you retrieve this data
> is left as an exercise for the reader... ;)
>
> Cheers,
>
> M.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Puppet Users" group.
> To post to this group, send email to puppet-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> puppet-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/puppet-users?hl=en.
>
>



-- 
Spenser Gilliland
Computer Engineer
Illinois Institute of Technology

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



[Puppet Users] Re: [Puppet-dev] Converting to Ruby DSL

2010-12-19 Thread Ken Barber
Thanks Luke.

So I've been making some notes here:

http://wiki.bob.sh/confluence/display/TECH/Ruby+DSL

And writing up some 
working examples:

https://github.com/bobsh/puppet-rubydsl-examples

... based on your notes 
and some digging. You wouldn't be able to take a look and correct me where 
I've tapped into the wrong part of the API? I realise I'm obviously touching 
internals that may change ... I just figure if I can figure out how to do it 
with internals then it shouldn't be hard to extend the DSL.

So obviously some of the ways I've done this should really be moved to 
convenience methods:

* Defaults: I presume the capitalisation of the first letter of a 
missing_method would indicate someone trying to set a default
* Vars: not sure how you make this work at the correct scope in ruby for 
proper 'my_var = "foo"' type sugar ... maybe a wrapper is more appropriate 
(a bit like create_resource).
* Relationships: I'm not sure how to do this yet, looking at the 
AST::Relationship bit there is a lot going on so I imagine I tap that, but 
how I do that without extending the dsl code itself is not obvious (so 
obviously I'm going to try that :-).

How would one go about extending it to deal with top scope? I'm guessing 
somehow you need to be able to populate @__created_ast_objects__ directly 
right from ResourceTypeAPI?

ken.

On Friday, December 10, 2010 6:47:42 AM UTC, Luke Kanies wrote:
>
> On Dec 8, 2010, at 11:09 AM, Ken Barber wrote:
>
> (cross posting here as I originally posted in puppet-users - I figure the 
> question is more of a dev one then for puppet-users)
>
>
> Hi everyone,
>
> I'm experimenting with converting some of my live puppet content to
> Ruby DSL and have found a few gaps I wouldn't mind some advice on. I'm
> not sure how many of you have already experimented in this arena yet.
>
> I've already read Dan Bode's excellent blog article on the subject:
> http://www.puppetlabs.com/blog/ruby-dsl/
>
> I know the Ruby DSL is quite new - but I figured perhaps some of these
> items deserve to be tickets (or perhaps documented) and I thought I'd
> ask first :-).
>
> Thanks for testing this.  As you say, it's still quite new, and definitely 
> incomplete, but as with most things we do, I wanted to get a simple thing 
> out and in the wild rather than wait for perfection before shipping.  This 
> kind of feedback is exactly what we need (although of course patches are 
> even better).
>
> 1. Defaults
>
> How do I set defaults in Ruby DSL? For example what is the ruby DSL
> equivalent to this:
>
>   Service {
> hasstatus => true
>   }
>
> This is one of the things I left out of my initial implementation.
>
> You might be able to figure out how to add it by patching one of the files 
> in lib/puppet/dsl.
>
> 2. Top scope
>
> I notice the convenience methodology does not work at 'top scope' for
> example
> this will fail:
>
>   file "/tmp/zzz", :content => "foo"
>
> But this will not:
>
>   node "default" do
> file "/tmp/zzz", :content => "foo"
>   end
>
> Is there a proper way to call resources without using the convenience
> methods? Or
> perhaps is there a way to define elements that reside in top scope?
>
> I made a decision when I did this not to pollute the top namespace - both 
> for cleanliness, and also for simplicity of implementation.  This has come 
> up a few times, though, so it's something that I'm happy to revisit.
>
> 3. Class resource
>
> I think Dan Bode already raised this as a bug:
> https://projects.puppetlabs.com/issues/5236
>
> The following returns an error 'method_missing':
>
>   hostclass :foo do
> notify "bar"
>   end
>   node "default" do
> hostclass "foo", :stage => "baz"
>   end
>
> This is because hostclass has not been defined as a convenience method
> it would seem. Just like issues 2 If someone knows
> a way to call a resource directly without requiring the convenience
> method that would be a decent enough work-around.
>
> Hmm.  It should be, but it looks like this is failing somewhere and has 
> been marked as a high priority bug. :/
>
> 4. exec Resource
>
> The 'exec' resource as a convenience method is overlapping with the
> ruby 'exec'
> method. So if you do this:
>
>   node "default" do
> exec "ls", :command => "/bin/ls"
>   end
>
> You get:
>
>   can't convert Hash into String on node obelisk.usr.bob.sh
>
> Returned from the Kernel.exec call.
>
> You should be able to use 'create_resource :exec, ...' here.
>
> 5. Referencing other resources
>
> I'm not quite clear how to reference other resources that already
> exist. This is obviously a problem for the 'require' attribute:
>
>   node "default" do
> package "foo", :ensure => "installed"
> service "foo", :enable => "true", :ensure => "running", :require
> => ???
>   end
>
> I believe the internal implementation allows you to do 'require => 
> [:package, "foo"]'.  I couldn't f

Re: [Puppet Users] Appending to Variables in a global context

2010-12-19 Thread Matthew Macdonald-Wallace
On Sun, 2010-12-19 at 04:40 -0600, Spenser Gilliland wrote:
> Matthew,
> 
> I'm a bit confused on your code,  how does an instance get added to the db?

Yeah, that's probably my fault... :D

My thought was that if you have a known path to the redmine instances
you could create a ruby class which iterates over the filesystem and
pulls each directory/installation name into a CSV string.

If you prefix your redmine database names with something obvious when
you install them, then you should be able to connect to the database
server and extract the table names that are relevant using "use
mysql;SELECT tableName from tables where tableName LIKE '%redmine_prefix
%';" or similar.

So the "db" which I spoke of is more of a datastore/list which contains
the currently installed redmine instances - how you retrieve this data
is left as an exercise for the reader... ;)

Cheers,

M.

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



Re: [Puppet Users] Appending to Variables in a global context

2010-12-19 Thread Spenser Gilliland
On Sun, Dec 19, 2010 at 4:40 AM, Spenser Gilliland  wrote:
> On Sun, Dec 19, 2010 at 4:14 AM, Matthew Macdonald-Wallace
>  wrote:
>> On Sun, 2010-12-19 at 01:51 -0600, Spenser Gilliland wrote:
>>> Yeap, I'm seeing that it doesn't exist yet either.  I'm thinking maybe
>>> I can use exported resources or maybe just an exec that increments a
>>> counter on the host.  Either way it's not very pretty.  My use case is
>>> as follows:
>>>
>>> In Debian, Redmine has the option of being installed as several
>>> instances controlled by a single debconf variable.  In order to
>>> utilize this feature, I need to supply debconf with the name of all
>>> instances of Redmine on the server. I've split this out into the
>>> following way:  A class called Redmine which installs the Redmine
>>> package and should hold an array of all the instances of Redmine to
>>> feed to debconf using the "responsefile" parameter.
>>>
>>> So I think I've come up with a solution in my head but it involves me
>>> guaranteeing that the redmine class is instantiated before any of the
>>> redmine::instances are defined.  Essentially, I'll use an
>>> environmental variable or file and clear it with the Redmine class and
>>> append to it for each redmine::instance.  Maybe like below?
>>>
>>> class redmine {
>>>     exec{"rm /tmp/instances && touch /tmp/instances"}
>>> }
>>>
>>> define redmine::instance
>>>    exec{"echo $name >> /tmp/instances"}
>>> }
>>
>> Can you "read" (from the file system or list the redmine databases in
>> mysql/postgresql server?) a list of installed instances?
>>
>> If so, why not setup a custom fact which has all the instances listed as
>> a csv string:
>>
>> == PSEUDO CODE!!! ==
>> instances = read_instances() # a class which connects to the db/file
>> # system to read in the instances and converts them to CSV format #
>>
>> Facter.add redmine_instances do
>>        setcode do
>>                instances
>>        end
>> end
>> ===
>>
>> and then template the /tmp/instances file using erb:
>>
>> == PSEUDO CODE!!! 
>> <% redmine_instances.each do |instance| -%>
>> instance
>> <% end -%>
>> ==
>>
>> Your manifest could then source this template onto the file system and
>> feed the file to debconf.
>>
>> It's a bit more long winded, however it means that if you want to add
>> instances, you just add an extra value to the fact.
>>
>> We use this technique to manage MySQL replication and it works really
>> well!
>>
>> Cheers,
>>
>> M.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Puppet Users" group.
>> To post to this group, send email to puppet-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> puppet-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/puppet-users?hl=en.
>>
>>
>
> Matthew,
>
> I'm a bit confused on your code,  how does an instance get added to the db?
>
> Matthias
>
> Approach one won't work, I am doing this from multiple different
> locations in the code.  Also because this is eventually something I
> want to hide I would probably just set it up using a variable in the
> node definition and have it read by the redmine class.
>
> node redmine {
>    $instances = ["john", "ted", "nancy"]
>    include redmine
>    redmine::instance{"john", "ted", "nancy"}
> }
>
> Approach two is similar to Matthews, so I have the same question how
> do I add an instance to the db?
>
> Thanks,
> Spenser
>
> --
> Spenser Gilliland
> Computer Engineer
> Illinois Institute of Technology
>

Also, just out of interest.  Would it make sense to create a feature
request for this?  I can think of quite a few instances where this
would be useful.

Thanks,
Spenser

-- 
Spenser Gilliland
Computer Engineer
Illinois Institute of Technology

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



Re: [Puppet Users] Appending to Variables in a global context

2010-12-19 Thread Spenser Gilliland
On Sun, Dec 19, 2010 at 4:14 AM, Matthew Macdonald-Wallace
 wrote:
> On Sun, 2010-12-19 at 01:51 -0600, Spenser Gilliland wrote:
>> Yeap, I'm seeing that it doesn't exist yet either.  I'm thinking maybe
>> I can use exported resources or maybe just an exec that increments a
>> counter on the host.  Either way it's not very pretty.  My use case is
>> as follows:
>>
>> In Debian, Redmine has the option of being installed as several
>> instances controlled by a single debconf variable.  In order to
>> utilize this feature, I need to supply debconf with the name of all
>> instances of Redmine on the server. I've split this out into the
>> following way:  A class called Redmine which installs the Redmine
>> package and should hold an array of all the instances of Redmine to
>> feed to debconf using the "responsefile" parameter.
>>
>> So I think I've come up with a solution in my head but it involves me
>> guaranteeing that the redmine class is instantiated before any of the
>> redmine::instances are defined.  Essentially, I'll use an
>> environmental variable or file and clear it with the Redmine class and
>> append to it for each redmine::instance.  Maybe like below?
>>
>> class redmine {
>>     exec{"rm /tmp/instances && touch /tmp/instances"}
>> }
>>
>> define redmine::instance
>>    exec{"echo $name >> /tmp/instances"}
>> }
>
> Can you "read" (from the file system or list the redmine databases in
> mysql/postgresql server?) a list of installed instances?
>
> If so, why not setup a custom fact which has all the instances listed as
> a csv string:
>
> == PSEUDO CODE!!! ==
> instances = read_instances() # a class which connects to the db/file
> # system to read in the instances and converts them to CSV format #
>
> Facter.add redmine_instances do
>        setcode do
>                instances
>        end
> end
> ===
>
> and then template the /tmp/instances file using erb:
>
> == PSEUDO CODE!!! 
> <% redmine_instances.each do |instance| -%>
> instance
> <% end -%>
> ==
>
> Your manifest could then source this template onto the file system and
> feed the file to debconf.
>
> It's a bit more long winded, however it means that if you want to add
> instances, you just add an extra value to the fact.
>
> We use this technique to manage MySQL replication and it works really
> well!
>
> Cheers,
>
> M.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Puppet Users" group.
> To post to this group, send email to puppet-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> puppet-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/puppet-users?hl=en.
>
>

Matthew,

I'm a bit confused on your code,  how does an instance get added to the db?

Matthias

Approach one won't work, I am doing this from multiple different
locations in the code.  Also because this is eventually something I
want to hide I would probably just set it up using a variable in the
node definition and have it read by the redmine class.

node redmine {
$instances = ["john", "ted", "nancy"]
include redmine
redmine::instance{"john", "ted", "nancy"}
}

Approach two is similar to Matthews, so I have the same question how
do I add an instance to the db?

Thanks,
Spenser

-- 
Spenser Gilliland
Computer Engineer
Illinois Institute of Technology

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



Re: [Puppet Users] Appending to Variables in a global context

2010-12-19 Thread Matthew Macdonald-Wallace
On Sun, 2010-12-19 at 01:51 -0600, Spenser Gilliland wrote:
> Yeap, I'm seeing that it doesn't exist yet either.  I'm thinking maybe
> I can use exported resources or maybe just an exec that increments a
> counter on the host.  Either way it's not very pretty.  My use case is
> as follows:
> 
> In Debian, Redmine has the option of being installed as several
> instances controlled by a single debconf variable.  In order to
> utilize this feature, I need to supply debconf with the name of all
> instances of Redmine on the server. I've split this out into the
> following way:  A class called Redmine which installs the Redmine
> package and should hold an array of all the instances of Redmine to
> feed to debconf using the "responsefile" parameter.
> 
> So I think I've come up with a solution in my head but it involves me
> guaranteeing that the redmine class is instantiated before any of the
> redmine::instances are defined.  Essentially, I'll use an
> environmental variable or file and clear it with the Redmine class and
> append to it for each redmine::instance.  Maybe like below?
> 
> class redmine {
> exec{"rm /tmp/instances && touch /tmp/instances"}
> }
> 
> define redmine::instance
>exec{"echo $name >> /tmp/instances"}
> }

Can you "read" (from the file system or list the redmine databases in
mysql/postgresql server?) a list of installed instances?

If so, why not setup a custom fact which has all the instances listed as
a csv string:

== PSEUDO CODE!!! ==
instances = read_instances() # a class which connects to the db/file  
# system to read in the instances and converts them to CSV format #

Facter.add redmine_instances do
setcode do 
instances
end
end
===

and then template the /tmp/instances file using erb:

== PSEUDO CODE!!! 
<% redmine_instances.each do |instance| -%>
instance
<% end -%>
==

Your manifest could then source this template onto the file system and
feed the file to debconf.

It's a bit more long winded, however it means that if you want to add
instances, you just add an extra value to the fact.

We use this technique to manage MySQL replication and it works really
well!

Cheers,

M.



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



Re: [Puppet Users] Appending to Variables in a global context

2010-12-19 Thread Matthias Saou
Spenser Gilliland  wrote:

> Yeap, I'm seeing that it doesn't exist yet either.  I'm thinking maybe
> I can use exported resources or maybe just an exec that increments a
> counter on the host.  Either way it's not very pretty.  My use case is
> as follows:
> 
> In Debian, Redmine has the option of being installed as several
> instances controlled by a single debconf variable.  In order to
> utilize this feature, I need to supply debconf with the name of all
> instances of Redmine on the server. I've split this out into the
> following way:  A class called Redmine which installs the Redmine
> package and should hold an array of all the instances of Redmine to
> feed to debconf using the "responsefile" parameter.
> 
> So I think I've come up with a solution in my head but it involves me
> guaranteeing that the redmine class is instantiated before any of the
> redmine::instances are defined.  Essentially, I'll use an
> environmental variable or file and clear it with the Redmine class and
> append to it for each redmine::instance.  Maybe like below?
> 
> class redmine {
> exec{"rm /tmp/instances && touch /tmp/instances"}
> }
> 
> define redmine::instance
>exec{"echo $name >> /tmp/instances"}
> }
> 
> I guess the next question is can i guarantee that my class will be
> instantiated prior to my instances and there is no possibility of the
> class being re-instantiated during the course of the puppet run?

The approach you're suggesting seems very ugly :-)

I'd suggest trying one of two different approaches :
 * Create a definition to which you'll pass an array of all instances,
   which will then call the redminde::instance for each. This only
   works of course if you're not trying to add new instances from
   various puppet classes/definitions.
 * Create a fact which returns all of the redmine instances of the
   puppet client. This has quite a few limitations, but might work
   depending on what you need exactly.

HTH,
Matthias

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



Re: [Puppet Users] Re: Referencing the same package from multiple classes

2010-12-19 Thread Ken Barber
Stefan - obviously my example doesn't include classes but I see what you 
mean. It is an interesting topic :-). So here was my example:

if !defined(Package["foo"]) {
  package {"foo": ensure => installed }
}

Now if I wanted to define a specific revision, trigger or behaviour I could 
understand why this would be problematic. For example:

if !defined(Package["foo"]) {
  package {"foo":
ensure => "1.2.3",
notify => Exec["bar"],
  }
}

Would be terrible - because I would lose the arguments if the package was 
defined elsewhere earlier. That would be dumb. Also - the reverse is true 
... by defining your own package you may be ruining someone else's package 
definition which defines arguments. Like you say - the ordering can cause 
problems.

FYI - The use-case where I would use the if !defined methodology would be 
when you are defining a re-usable module that you know may (but not always) 
conflict with another. Nothing is a silver bullet it seems in puppet, and I 
have had to use this method at least once or twice to avoid stepping on 
pre-existing content that I can't influence :-).

ken.

On Sunday, December 19, 2010 8:53:18 AM UTC, stefan.schulte wrote:
>
> On Sat, Dec 18, 2010 at 11:46:50AM -0800, Ken Barber wrote:
> > Can you elaborate?
> > 
> > On Saturday, December 18, 2010 7:23:57 PM UTC, kc7zzv wrote:
> > >
> > >
> > > On Dec 18, 2010, at 3:50 AM, Ken Barber wrote:
> > >
> > > > For the record, an alternative that I don't believe was mentioned is 
> to 
> > > do something like:
> > > > 
> > > > if !defined(Package["foo"]) {
> > > >   package {"foo": ensure => installed }
> > > > }
> > >
> > > In general this is a bad idea though.  Mostly because it can surprise 
> you 
> > > in bad ways.
> > >
> > >
>
> Its an ordering issue. Example
>
>   node default {
> include foo
> if defined(Exec['uname']) {
>   include bar
> }
>   }
>
>   class foo {
> exec { 'uname': command => '/usr/bin/uname' }
> notice("Class[foo] applied for defaultnode")
>   }
>   class bar {
> notice("Class[bar] applied for defaultnode")
>   }
>
> This works but if you include foo after the ifstatement then bar will
> not be included. If you have a complex dependency chain the right order
> may not be as obvious as in this example (at least I dont know in which
> order puppet parses complex and nested class structures [and in my
> opinion I should not have to know it])
>
> -Stefan
>
>

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



Re: [Puppet Users] Re: Referencing the same package from multiple classes

2010-12-19 Thread Stefan Schulte
On Sat, Dec 18, 2010 at 11:46:50AM -0800, Ken Barber wrote:
> Can you elaborate?
> 
> On Saturday, December 18, 2010 7:23:57 PM UTC, kc7zzv wrote:
> >
> >
> > On Dec 18, 2010, at 3:50 AM, Ken Barber wrote:
> >
> > > For the record, an alternative that I don't believe was mentioned is to 
> > do something like:
> > > 
> > > if !defined(Package["foo"]) {
> > >   package {"foo": ensure => installed }
> > > }
> >
> > In general this is a bad idea though.  Mostly because it can surprise you 
> > in bad ways.
> >
> >

Its an ordering issue. Example

  node default {
include foo
if defined(Exec['uname']) {
  include bar
}
  }

  class foo {
exec { 'uname': command => '/usr/bin/uname' }
notice("Class[foo] applied for defaultnode")
  }
  class bar {
notice("Class[bar] applied for defaultnode")
  }

This works but if you include foo after the ifstatement then bar will
not be included. If you have a complex dependency chain the right order
may not be as obvious as in this example (at least I dont know in which
order puppet parses complex and nested class structures [and in my
opinion I should not have to know it])

-Stefan


pgpKjJX0SnTv9.pgp
Description: PGP signature