If you had the following state:
and maspwr already existed with the following groups: maspwr, foobar. This state will fail on its first run.
The reason is that user.getent (which is called from the user state, https://github.com/saltstack/salt/blob/develop/salt/states/user.py#L54) seems to return a cached version, https://github.com/saltstack/salt/blob/develop/salt/modules/useradd.py#L174. If you rerun the state the changes to the groups (which were applied successfully) will be picked up and everything passes.
I believe the fix will be to remove the cached user.getent either conditionally or outright. Let me know if you need more info.
I'm pretty sure this was fixed in git a while back. Checking the source now.
Ahh, I fixed this in user.getent, not group.info (which is still returning data from __context__.
@thatch45 The issue here is that the data from the dunder context dict is being returned. This is a bad idea for states since we want to detect changes.
I removed the setting of the context variable for useradd_getent in a different issue a couple weeks ago. However, I do think that there is a good case to be made for putting user/group data in the dunder context dict. So, I was thinking of doing the following:
What do you think? If you like it, what would you like the kwarg to be?
Chatted with @thatch45 just a few mins ago, and there's a much simpler way. The data in __context__ for user.getent and group.list_groups can simply be cleared before the user or group state does that lookup, and this will make those functions retrieve the information again rather than returning the cached data.
Seems like that style could be prone to error, but y'all know the code base better than I. :)
Well, so would doing it the other way, since you'd have to override the default behavior of using the data from __context__. Either way, you're doing something to invalidate the cached data. Simply clearing that data is the path of least resistance, since it doesn't involve extra code being added to the useradd and groupadd modules.