puppet user context

53 views
Skip to first unread message

Robert Turk

unread,
Jan 16, 2014, 2:12:42 AM1/16/14
to puppet...@googlegroups.com
Good morning,

I have a question concerning puppet and modifying user data. I am on Mac
OS X 10.8.5 with puppet 3.4.2.
I would like to run a manifest with the following content:

file { "/Users/${id}/Desktop/testfile":
ensure => file,
}
file { "/usr/testfile":
ensure => file,
}

For this manifest you need root access and you have to know the current
logged in user.
But the fact $id is, of course, "root" because I have to run this
manifest as root.

So how can I get the current logged in user as a variable?

Thanks in advance.

Kind regards.
Robert

Andrey Kozichev

unread,
Jan 16, 2014, 7:50:33 AM1/16/14
to puppet...@googlegroups.com
Do you need to run this only for logged in users?
You can use facter fact to return logged in users and use it in your manifest.

Andrey



Robert

--
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 puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/52D7866A.1040909%40reproflex.de.
For more options, visit https://groups.google.com/groups/opt_out.

Robert Turk

unread,
Jan 17, 2014, 2:39:14 AM1/17/14
to puppet...@googlegroups.com

Am 16.01.14 13:50, schrieb Andrey Kozichev:
> Do you need to run this only for logged in users?
No not really... You suggest I could do something like checking which
users exist on the machine and then run it for these users
ignoring if they are logged in or not?

> You can use facter fact to return logged in users and use it in your
> manifest.
Do you mean building a custom fact for this value?

Robert


Andrey Kozichev

unread,
Jan 17, 2014, 3:17:51 AM1/17/14
to puppet...@googlegroups.com

Not sure, what is your task.
Where are you getting users from? Is it everyone or do you have defined list? 


Andrey


--
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 puppet-users+unsubscribe@googlegroups.com.

Robert Turk

unread,
Jan 17, 2014, 4:15:47 AM1/17/14
to puppet...@googlegroups.com

Am 17.01.14 09:17, schrieb Andrey Kozichev:
> Not sure, what is your task.
> Where are you getting users from? Is it everyone or do you have
> defined list?

I just want to put some plist files in the user library to provide some
setings.
It is for every user, so I could maybe check the "/Users" folder and
place the files
into every user's home folder I can find.

Robert


Andrey Kozichev

unread,
Jan 17, 2014, 5:43:12 AM1/17/14
to puppet...@googlegroups.com

You can get list of directories under /Users from facter and then build an array out of it and use this in your manifest.

--
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 puppet-users+unsubscribe@googlegroups.com.

Robert Turk

unread,
Jan 20, 2014, 3:02:31 AM1/20/14
to puppet...@googlegroups.com

Am 17.01.14 11:43, schrieb Andrey Kozichev:
> You can get list of directories under /Users from facter and then
> build an array out of it and use this in your manifest.
Thanks for your help. I will try this...

Robert

Robert Turk

unread,
Jan 28, 2014, 8:35:02 AM1/28/14
to puppet...@googlegroups.com

Am 20.01.14 09:02, schrieb Robert Turk:
> You can get list of directories under /Users from facter and then
> build an array out of it and use this in your manifest.
I tested your solution and here is what I have done:

I created a custom fact which returns a list of directories under /Users:
facter local_user_list => user1,user2

Next in puppet I created the following code:

class wallpaper_plist {
$array_userlist=split($local_user_list,',')
case $macosx_productversion_major {
'10.8': { $plist_name = 'com.apple.desktop_10.8.plist' }
'10.6': { $plist_name = 'com.apple.desktop_10.6.plist' }
default: { warn( 'macosx_productversion_major does not
match 10.8 or 10.6' ) }
}
define user_resource {
file {
"/Users/${name}/Library/Preferences/com.apple.desktop.plist":
owner => "${name}",
group => 'staff',
mode => 600,
ensure => file,
source => "puppet:///modules/wallpaper_plist/${plist_name}",
}
}
user_resource { $array_userlist: }
}

This code works, but it gives me a directory for the file resource. And
not a file like it is said in the code.

Any ideas?

Robert

Jose Luis Ledesma

unread,
Jan 28, 2014, 12:34:02 PM1/28/14
to puppet...@googlegroups.com
Could be that the ${plist_name} is undef inside the define? You could try adding a notify inside the define to check which value it has.

Regards,

Robert Turk

unread,
Jan 29, 2014, 3:56:01 AM1/29/14
to puppet...@googlegroups.com

Am 28.01.14 18:34, schrieb Jose Luis Ledesma:
> Could be that the ${plist_name} is undef inside the define? You could try adding a notify inside the define to check which value it has.
If I use a notify inside the defined resource I get a duplicate
declaration error, so I chnaged the code to use a static filename
instead of the $plist_name variable and it worked.

But using a notify outside the defined resource works and gets me the
correct value for the variable $plist_name...
So why is it not working? Is it an other scope or namespace?

Robert

José Luis Ledesma

unread,
Jan 29, 2014, 4:05:13 AM1/29/14
to puppet...@googlegroups.com

I think so, but I'm not an expert .

Could you try adding the "full path"

$classname::plist_name?

Regards

--
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 puppet-users+unsubscribe@googlegroups.com.

Robert Turk

unread,
Jan 29, 2014, 4:34:49 AM1/29/14
to puppet...@googlegroups.com

Am 29.01.14 10:05, schrieb José Luis Ledesma:
> Could you try adding the "full path"
Thanks for your help. Using "${wallpaper_plist::plist_name}" does the
trick. :)

Robert

Reply all
Reply to author
Forward
0 new messages