ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
92 stars 19 forks source link

Proposal: Add graceful query state to win_domain_group module #176

Closed cphillipsmcp closed 3 years ago

cphillipsmcp commented 4 years ago

Proposal: Add graceful query state to win_domain_group module

Author: Christopher Phillip <@cphillipsmcp>

Date: 2019-11-22

Motivation

In its current revision, query functionality is present, but not as elegant as the "win_domain_user" module where values, such as, "present" and "absent" are returned using a "query" state.

Problems

What problems exist that this proposal will solve?

Solution proposal

... if (-not $check_mode) { $group = Get-ADGroup -Filter {Name -eq $name} -Properties * @extra_args if (!$group) { $result.name = $name $result.msg = "Group '$name' is absent" $result.state = "absent" } else { $result.sid = $group.SID.Value $result.description = $group.Description $result.distinguished_name = $group.DistinguishedName $result.display_name = $group.DisplayName $result.name = $group.Name $result.canonical_name = $group.CanonicalName $result.guid = $group.ObjectGUID $result.protected_from_accidental_deletion = $group.ProtectedFromAccidentalDeletion $result.managed_by = $group.ManagedBy $result.group_scope = ($group.GroupScope).ToString() $result.category = ($group.GroupCategory).ToString() $result.msg = "Group '$name' is present" $result.state = "present"

    if ($null -ne $attributes) {
        $result.attributes = @{}
        foreach ($attribute in $attributes.GetEnumerator()) {
            $attribute_name = $attribute.Name
            $result.attributes.$attribute_name = $group.$attribute_name
        }
    }
}
jamescassell commented 4 years ago

This one should be moved over to the main ansible repo. This repo is for wide sweeping changes.