Hi,
I'm trying to write a custom function to get the primary group of a given user.
The following works in plain Ruby:
def primary_group_of(user:)
require 'etc'
return Etc.getgrgid(Etc.getpwnam(user).gid).name
end
puts primary_group_of(user: 'username' )
Translated into a Puppet function, it looks like:
Puppet::Functions.create_function(:'mylib::primary_group_of') do
dispatch :primary_group_of do
param 'String', :user
end
def primary_group_of(user)
require 'etc'
return Etc.getgrgid(Etc.getpwnam(user).gid).name
end
end
But this, when executed from within a simple file resource like this
class testing {
file { '/tmp/test':
content => 'foo',
owner => 'username',
group => mylib::primary_group_of('username'),
}
}
Only yields: "...Error while evaluating a Function Call, undefined method `gid'
for nil:NilClass..."
Any hints as to what could be wrong here? Seems it doesn't do the "require",
but I'm not sure. Documentation doesn't say anything about using Ruby library
modules.
Thanks...
Dirk
Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenText (tm) Discovery | Recommind
Email: [email protected]<mailto:[email protected]>
Website: www.recommind.de<http://www.recommind.de/>
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Vertretungsberechtigte Geschäftsführer John Marshall Doolittle, Gordon Davies,
Roger Illing, Registergericht Amtsgericht Bonn, Registernummer HRB 10646
This e-mail may contain confidential and/or privileged information. If you are
not the intended recipient (or have received this e-mail in error) please
notify the sender immediately and destroy this e-mail. Any unauthorized
copying, disclosure or distribution of the material in this e-mail is strictly
forbidden
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten
haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail.
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht
gestattet.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/BYAPR15MB2405BBEF9F2C108F0B2D54D0AADE0%40BYAPR15MB2405.namprd15.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.