ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Salt grain to retrieve users present on minion (Windows)

    IT Discussion
    salt saltstack windows
    2
    6
    2.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      flaxking
      last edited by

      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:

      presentusersgrain.py

      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 run salt '*' grains.items to see your new grain

      1 Reply Last reply Reply Quote 3
      • scottalanmillerS
        scottalanmiller
        last edited by

        Salt seems like the obvious tool for desktop administration to me!

        F 1 Reply Last reply Reply Quote 1
        • F
          flaxking @scottalanmiller
          last edited by flaxking

          @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.

          scottalanmillerS 1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @flaxking
            last edited by

            @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.

            F 1 Reply Last reply Reply Quote 1
            • F
              flaxking @scottalanmiller
              last edited by

              @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?

              scottalanmillerS 1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller @flaxking
                last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post