[Puppet Users] Re: Using variables in virtual resources

2009-10-02 Thread Michael Gliwinski

On Friday 02 October 2009 13:41:44 Michael Gliwinski wrote:
> On Friday 02 October 2009 07:35:57 Erling wrote:
> > On 28 Sep, 19:44, Eric Gerlach  wrote:
> > > You might be able to do something like:
> > >
> > > realize User[kenneth]
> > >
> > > User[kenneth] {
> > >         groups => $server_type ? {
> > >                 typeA => "wheel",
> > >                 default => undef,
> > >         }
> > >
> > > }
> > >
> > > to realize it the way you want.  Haven't tried anything like that
> > > though. Maybe someone else can comment if it works.
> >
> > I have tried this:
> >
> >
> > node 'mynode.local' {
> >
> > $server_type = "webserver"
> >
> > adduser { "joe":
> > server_type => $server_type,
> > user_name => "joe",
> > }
> > }
> >
> > define adduser ( $user_name, $server_type ) {
> >
> > realize User[$user_name]
> > realize Group[$user_name]
> >
> > User[$user_name] {
> > groups => $server_type ? {
> > webserver => wheel,
> > default => $user_name,
> > },
> > }
> > }
> >
> >
> >
> > @group { "joe":
> >  ensure => present,
> >  gid => 1234,
> >  allowdupe => false
> > }
> >
> > @user {"joe":
> >  ensure => present,
> >  managehome => true,
> >  uid => 1234,
> >  gid => 1234,
> >  home => "/home/joe",
> >  shell => "/bin/bash",
> >  comment => "Joe",
> >  password => '$1$ij21Zc04$MwyqTQP2fXc0BqMIjtz5b/',
> > }
> >
> > When running puppetd on mynode.local I get this message:
> >
> > notice: Ignoring cache
> > err: Could not retrieve catalog: Only subclasses can override
> > parameters at /etc/puppet/manifests/classes/adduser.pp:11
> > warning: Not using cache on failed catalog
> >
> > Best regards,
> >
> > Erling Ringen Elvsrud
>
> You should try re-organizing this so that you have your resources (here
> users) defined in a class, e.g.
>
> class all_users {
> @user {"joe":
> ensure => present,
> ...
> groups => $servertype ? {
> webserver => wheel,
> default => $user_name
> }
> }
> }
>
> node 'mynode.local' {
> $server_type = "webserver"
> incldue all_users
> }
>
> This is a simpliest example, you may still use a define and have to watch
> out for scoping rules, but that's the general idea.
>
> Regards,

Aaand of course I made a mistake :O  when you're using virtual resources you 
have to realize them somewhere, e.g.:

class all_users {
@user {"joe":
ensure => present,
...
groups => $servertype ? {
webserver => wheel,
default => $user_name
}
}
}

node 'mynode.local' {
$server_type = "webserver"
incldue all_users
realize(User["joe"])
}

Again, note that this is simplistic, you usually don't realize resources 
directly in the nodes.

-- 
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 
supp...@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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~--~~~~--~~--~--~---



[Puppet Users] Re: Using variables in virtual resources

2009-10-02 Thread Michael Gliwinski

On Friday 02 October 2009 07:35:57 Erling wrote:
> On 28 Sep, 19:44, Eric Gerlach  wrote:
> > You might be able to do something like:
> >
> > realize User[kenneth]
> >
> > User[kenneth] {
> >         groups => $server_type ? {
> >                 typeA => "wheel",
> >                 default => undef,
> >         }
> >
> > }
> >
> > to realize it the way you want.  Haven't tried anything like that though.
> > Maybe someone else can comment if it works.
>
> I have tried this:
>
>
> node 'mynode.local' {
>
> $server_type = "webserver"
>
> adduser { "joe":
> server_type => $server_type,
> user_name => "joe",
> }
> }
>
> define adduser ( $user_name, $server_type ) {
>
> realize User[$user_name]
> realize Group[$user_name]
>
> User[$user_name] {
> groups => $server_type ? {
> webserver => wheel,
> default => $user_name,
> },
> }
> }
>
>
>
> @group { "joe":
>  ensure => present,
>  gid => 1234,
>  allowdupe => false
> }
>
> @user {"joe":
>  ensure => present,
>  managehome => true,
>  uid => 1234,
>  gid => 1234,
>  home => "/home/joe",
>  shell => "/bin/bash",
>  comment => "Joe",
>  password => '$1$ij21Zc04$MwyqTQP2fXc0BqMIjtz5b/',
> }
>
> When running puppetd on mynode.local I get this message:
>
> notice: Ignoring cache
> err: Could not retrieve catalog: Only subclasses can override
> parameters at /etc/puppet/manifests/classes/adduser.pp:11
> warning: Not using cache on failed catalog
>
> Best regards,
>
> Erling Ringen Elvsrud
>

You should try re-organizing this so that you have your resources (here users) 
defined in a class, e.g.

class all_users {
@user {"joe":
ensure => present,
...
groups => $servertype ? {
webserver => wheel,
default => $user_name
}
}
}

node 'mynode.local' {
$server_type = "webserver"
incldue all_users
}

This is a simpliest example, you may still use a define and have to watch out 
for scoping rules, but that's the general idea.

Regards,

-- 
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 
supp...@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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~--~~~~--~~--~--~---



[Puppet Users] Re: Using variables in virtual resources

2009-10-01 Thread Erling

On 28 Sep, 19:44, Eric Gerlach  wrote:
> You might be able to do something like:
>
> realize User[kenneth]
>
> User[kenneth] {
>         groups => $server_type ? {
>                 typeA => "wheel",
>                 default => undef,
>         }
>
> }
>
> to realize it the way you want.  Haven't tried anything like that though.
> Maybe someone else can comment if it works.


I have tried this:


node 'mynode.local' {

$server_type = "webserver"

adduser { "joe":
server_type => $server_type,
user_name => "joe",
}
}

define adduser ( $user_name, $server_type ) {

realize User[$user_name]
realize Group[$user_name]

User[$user_name] {
groups => $server_type ? {
webserver => wheel,
default => $user_name,
},
}
}



@group { "joe":
 ensure => present,
 gid => 1234,
 allowdupe => false
}

@user {"joe":
 ensure => present,
 managehome => true,
 uid => 1234,
 gid => 1234,
 home => "/home/joe",
 shell => "/bin/bash",
 comment => "Joe",
 password => '$1$ij21Zc04$MwyqTQP2fXc0BqMIjtz5b/',
}

When running puppetd on mynode.local I get this message:

notice: Ignoring cache
err: Could not retrieve catalog: Only subclasses can override
parameters at /etc/puppet/manifests/classes/adduser.pp:11
warning: Not using cache on failed catalog

Best regards,

Erling Ringen Elvsrud

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~--~~~~--~~--~--~---



[Puppet Users] Re: Using variables in virtual resources

2009-09-29 Thread Bjørn Dyre Dyresen
Hi, there

Im looking into the same thing. Did you come up with a decent solution?

Regards
Bjørn Dyresen

2009/9/28 Eric Gerlach 

>
> On Fri, Sep 18, 2009 at 09:08:37AM +0200, Kenneth Holter wrote:
> > Hi.
> >
> >
> > I've defined a virtual user "kenneth", and depending on a variable in the
> > node definiton I'd like to add the users to different groups. Consider
> this
> > example:
> >
> > ##  Code start
> >
> > node "server.example.com" {
> >$server_type = "typeA"
> >
> >realize User[kenneth]
> >
> > }
> >
> >   @user {"kenneth":
> > ensure => present,
> > uid => 1000,
> > gid => 1000,
> > groups => $server_type ? {
> >typeA => "wheel",
> >default => undef,
> > },
> >
> > home => "/home/kenneth",
> > shell => "/bin/bash",
> > comment => "A comment",
> > password => ''
> >
> >  }
> >
> > ## Code end
> >
> > If I add the user to an ordinary class (like "class user_kenneth")
> instead
> > of defining it as a virtual resource, everything works fine. But when
> using
> > a virtual definition like this, the variable "server_type" doesn't seem
> to
> > have any effect on the if statement "groups". Am I doing something wrong,
> or
> > is this not supposed to work? I'm running version 0.24.4.
>
> I've been off for over a week, so I just noticed you never got an answer to
> this question.  The variables are filled out at the time the virtual
> resource
> is defined, not at the time it's realized.
>
> You might be able to do something like:
>
> realize User[kenneth]
>
> User[kenneth] {
> groups => $server_type ? {
>typeA => "wheel",
>default => undef,
>}
> }
>
> to realize it the way you want.  Haven't tried anything like that though.
> Maybe someone else can comment if it works.
>
> Cheers,
>
> --
> Eric Gerlach, Network Administrator
> Federation of Students
> University of Waterloo
> p: (519) 888-4567 x36329
> e: egerl...@feds.uwaterloo.ca
>
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~--~~~~--~~--~--~---



[Puppet Users] Re: Using variables in virtual resources

2009-09-28 Thread Eric Gerlach

On Fri, Sep 18, 2009 at 09:08:37AM +0200, Kenneth Holter wrote:
> Hi.
> 
> 
> I've defined a virtual user "kenneth", and depending on a variable in the
> node definiton I'd like to add the users to different groups. Consider this
> example:
> 
> ##  Code start
> 
> node "server.example.com" {
>$server_type = "typeA"
> 
>realize User[kenneth]
> 
> }
> 
>   @user {"kenneth":
> ensure => present,
> uid => 1000,
> gid => 1000,
> groups => $server_type ? {
>typeA => "wheel",
>default => undef,
> },
> 
> home => "/home/kenneth",
> shell => "/bin/bash",
> comment => "A comment",
> password => ''
> 
>  }
> 
> ## Code end
> 
> If I add the user to an ordinary class (like "class user_kenneth") instead
> of defining it as a virtual resource, everything works fine. But when using
> a virtual definition like this, the variable "server_type" doesn't seem to
> have any effect on the if statement "groups". Am I doing something wrong, or
> is this not supposed to work? I'm running version 0.24.4.

I've been off for over a week, so I just noticed you never got an answer to
this question.  The variables are filled out at the time the virtual resource
is defined, not at the time it's realized.

You might be able to do something like:

realize User[kenneth]

User[kenneth] {
groups => $server_type ? {
typeA => "wheel",
default => undef,
}
}

to realize it the way you want.  Haven't tried anything like that though.
Maybe someone else can comment if it works.

Cheers,

-- 
Eric Gerlach, Network Administrator
Federation of Students
University of Waterloo
p: (519) 888-4567 x36329
e: egerl...@feds.uwaterloo.ca

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~--~~~~--~~--~--~---