1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Added ability to specify destination OU when joining a domain (#22393)

* Added ability to specify destination OU when joining a domain

* Updated win_domain_membership documentation to include OU destination option.

* Updated python to include version

* Additional info in the docs
This commit is contained in:
McBadass 2017-07-20 18:50:54 -06:00 committed by Jordan Borean
parent c9b474cb33
commit 0229476c44
2 changed files with 21 additions and 4 deletions

View file

@ -99,7 +99,8 @@ Function Join-Domain {
[string] $dns_domain_name, [string] $dns_domain_name,
[string] $new_hostname, [string] $new_hostname,
[string] $domain_admin_user, [string] $domain_admin_user,
[string] $domain_admin_password [string] $domain_admin_password,
[string] $domain_ou_path
) )
Write-DebugLog ("Creating credential for user {0}" -f $domain_admin_user) Write-DebugLog ("Creating credential for user {0}" -f $domain_admin_user)
@ -117,7 +118,13 @@ Function Join-Domain {
$add_args["NewName"] = $new_hostname $add_args["NewName"] = $new_hostname
} }
Write-DebugLog "calling Add-Computer"
if($domain_ou_path){
Write-DebugLog "adding OU destination arg to Add-Computer args"
$add_args["OUPath"] = $domain_ou_path
}
$argstr = $add_args | Out-String
Write-DebugLog "calling Add-Computer with args: $argstr"
$add_result = Add-Computer @add_args $add_result = Add-Computer @add_args
Write-DebugLog ("Add-Computer result was \n{0}" -f $add_result | Out-String) Write-DebugLog ("Add-Computer result was \n{0}" -f $add_result | Out-String)
@ -172,6 +179,7 @@ $hostname = Get-AnsibleParam $params "hostname"
$workgroup_name = Get-AnsibleParam $params "workgroup_name" $workgroup_name = Get-AnsibleParam $params "workgroup_name"
$domain_admin_user = Get-AnsibleParam $params "domain_admin_user" -failifempty $result $domain_admin_user = Get-AnsibleParam $params "domain_admin_user" -failifempty $result
$domain_admin_password = Get-AnsibleParam $params "domain_admin_password" -failifempty $result $domain_admin_password = Get-AnsibleParam $params "domain_admin_password" -failifempty $result
$domain_ou_path = Get-AnsibleParam $params "domain_ou_path"
$log_path = Get-AnsibleParam $params "log_path" $log_path = Get-AnsibleParam $params "log_path"
$_ansible_check_mode = Get-AnsibleParam $params "_ansible_check_mode" -default $false $_ansible_check_mode = Get-AnsibleParam $params "_ansible_check_mode" -default $false
@ -221,6 +229,10 @@ Try {
Write-DebugLog "adding hostname change to domain-join args" Write-DebugLog "adding hostname change to domain-join args"
$join_args.new_hostname = $hostname $join_args.new_hostname = $hostname
} }
If($domain_ou_path -ne $null){ # If OU Path is not empty
Write-DebugLog "adding domain_ou_path to domain-join args"
$join_args.domain_ou_path = $domain_ou_path
}
$join_result = Join-Domain @join_args $join_result = Join-Domain @join_args
} }
@ -276,4 +288,3 @@ Catch {
Throw Throw
} }

View file

@ -45,6 +45,11 @@ options:
hostname: hostname:
description: description:
- the desired hostname for the Windows host - the desired hostname for the Windows host
domain_ou_path:
description:
- The desired OU path for adding the computer object.
- This is only used when adding the target host to a domain, if it is already a member then it is ignored.
version_added: "2.4"
state: state:
description: description:
- whether the target host should be a member of a domain or workgroup - whether the target host should be a member of a domain or workgroup
@ -80,6 +85,7 @@ EXAMPLES = '''
hostname: mydomainclient hostname: mydomainclient
domain_admin_user: testguy@ansible.vagrant domain_admin_user: testguy@ansible.vagrant
domain_admin_password: password123! domain_admin_password: password123!
domain_ou_path: "OU=Windows,OU=Servers,DC=ansible,DC=vagrant"
state: domain state: domain
register: domain_state register: domain_state