Hi there,
i want to create a user. The name of the user is based on the
hostname. If my hostname is ,,notebook12'''', my user is
,,user12''''.
The idea is to replace ,,notebook'''' with
,,user'''' and create fact
called ,,username''''.
But my fact doesn''t work:
Facter.add("username") do
setcode do
$username = Facter.hostname
$username.sub!(/notebook/, ''user'')
puts $username
end
end
I suspect the problem is in the third line ;).
Any help is greatly appreciated.
MFG,
Karsten
--
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
http://groups.google.com/group/puppet-users?hl=en.
Nigel Kersten
2010-Dec-13 17:41 UTC
Re: [Puppet Users] Using one fact to make another fact
On Mon, Dec 13, 2010 at 8:33 AM, tecneeq <tecneeq@googlemail.com> wrote:> Hi there, > > i want to create a user. The name of the user is based on the > hostname. If my hostname is ,,notebook12'''', my user is ,,user12''''. > > The idea is to replace ,,notebook'''' with ,,user'''' and create fact > called ,,username''''. > > But my fact doesn''t work: > > Facter.add("username") do > setcode do > $username = Facter.hostnameFacter.value(:hostname)> $username.sub!(/notebook/, ''user'') > puts $username > end > end > > I suspect the problem is in the third line ;). > > Any help is greatly appreciated. > > MFG, > > Karsten > > -- > 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 http://groups.google.com/group/puppet-users?hl=en. > >-- Nigel Kersten - Puppet Labs - http://www.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 http://groups.google.com/group/puppet-users?hl=en.
>> Facter.add("username") do >> setcode do >> $username = Facter.hostname > > Facter.value(:hostname) > >> $username.sub!(/notebook/, ''user'') >> puts $usernameand no need to puts, facter expects $username to be returned. But beware that $username is a global variable and you should avoid that one, hence you just write it without $ ~pete -- 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 http://groups.google.com/group/puppet-users?hl=en.