Skip to content

[Request] user_role module should take a list of roles, and (optionally) remove users from the roles not in the list #321

@harCamConsulting

Description

@harCamConsulting

Is your feature request related to a problem? Please describe.
Using user_role module could lead to permissions build up over time if users not removed from roles more easily.
Currently when I need to change the roles for a user, I would add another whole play and edit it. If I need to remove a user from having access to a database, I need to know the roles they were added to (which isn't necessarily always known)
This enhancement would make it easier to remove users from roles they don't need while leaving in ones that they do. It would also make the playbooks read more idempotently

Describe the solution you'd like
The parameter "role" should take a list of strings. A string could be converted into a list with one item in it if needed. The plugin would then cycle over each of the roles the user already has. If the users current roles has extra than the list desired, they would be removed. If the user is missing roles that are desired, they would be added.

The powershell command something like this could be used to get the list of current roles the user has into an array:
$currentroles = get-dbadbrolemember -database $databasename -sqlinstance $sqlinstance -sqlcredential $cred | where-object {$_.username -eq $username} | select -expandproperty role

The list from that could then be used in a compare-object command against the list passed from ansible to find the changes needed (if any), e.g.:

$diffs = Compare-Object $currentroles $desired
$to_add = $diffs | Where-Object {$_.sideindicator -eq '=>'} | select -ExpandProperty inputobject
$to_del = $diffs | Where-Object {$_.sideindicator -eq '<='} | select -ExpandProperty inputobject

Describe alternatives you've considered
Considered doing in the playbook using either custom powershell scripts or SQL scripts, but this looks messier and is harder to maintain

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions