Salt grain to retrieve users present on minion (Windows)
-
I've seen some doubts around about how useful Salt would be for desktop administration, so I thought I would share my Salt grain that makes things easier for me. It gives you a list of users that have profiles on that minion. So the end result is that you can do this in your states:
{% for usr in grains['present_users'] %} C:\Users\{{ usr }}\AppData\Local\Something: file.directory: - makedirs: True {% endfor %}
This has only been tested on Salt 2017.7.1, and it will definitely break with the next major release because they are changing some things that it relies on.
To use this custom grain, create a _grains folder within your salt states folder/repo, then save this as a file there:
import socket import salt.utils if salt.utils.is_windows(): import salt.utils.winapi import wmi def presentusers(): if salt.utils.is_windows(): with salt.utils.winapi.Com(): wmi_c = wmi.WMI() userprofiles = [x.LocalPath.split('\\') for x in wmi_c.Win32_UserProfile()] sysprof = ['systemprofile', 'ServiceProfiles'] userlist = [x[-1] for x in userprofiles if not any(word in x for word in sysprof)] return {'present_users': userlist} return {'present_users': 'n/a'}
Then run
salt '*' saltutil.sync_grains
to sync the custom grain to your minions. Now runsalt '*' grains.items
to see your new grain -
Salt seems like the obvious tool for desktop administration to me!
-
@scottalanmiller said in Salt grain to retrieve users present on minion (Windows):
Salt seems like the obvious tool for desktop administration to me!
And the thing is that automating desktop configuration has been the norm for longer than automating server configuration (at least in the Windows world), just with crappier tools.
-
@flaxking said in Salt grain to retrieve users present on minion (Windows):
@scottalanmiller said in Salt grain to retrieve users present on minion (Windows):
Salt seems like the obvious tool for desktop administration to me!
And the thing is that automating desktop configuration has been the norm for longer than automating server configuration (at least in the Windows word), just with crappier tools.
Yeah, very weird that people don't see this. @QuixoticJeremy actually presented on using tools like Salt to manage desktops at MangoCon 2017 a few months ago.
-
@scottalanmiller said in Salt grain to retrieve users present on minion (Windows):
@flaxking said in Salt grain to retrieve users present on minion (Windows):
@scottalanmiller said in Salt grain to retrieve users present on minion (Windows):
Salt seems like the obvious tool for desktop administration to me!
And the thing is that automating desktop configuration has been the norm for longer than automating server configuration (at least in the Windows word), just with crappier tools.
Yeah, very weird that people don't see this. @QuixoticJeremy actually presented on using tools like Salt to manage desktops at MangoCon 2017 a few months ago.
No MangoCon 2017 videos up yet?
-
@flaxking said in Salt grain to retrieve users present on minion (Windows):
@scottalanmiller said in Salt grain to retrieve users present on minion (Windows):
@flaxking said in Salt grain to retrieve users present on minion (Windows):
@scottalanmiller said in Salt grain to retrieve users present on minion (Windows):
Salt seems like the obvious tool for desktop administration to me!
And the thing is that automating desktop configuration has been the norm for longer than automating server configuration (at least in the Windows word), just with crappier tools.
Yeah, very weird that people don't see this. @QuixoticJeremy actually presented on using tools like Salt to manage desktops at MangoCon 2017 a few months ago.
No MangoCon 2017 videos up yet?
No, waiting on @Minion-Queen