Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

membership - Improve domainjoin+rename process #145

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

pluto00987
Copy link
Contributor

SUMMARY

This is for situations when joining to a domain with a hostname change too.

When using the Add-Computer cmdlet with NewName specified the process occurs as such:

  1. Joins computer to domain using current/old hostname
  2. Renames computer and AD computer account to new hostname

This generally works except in cases where the target AD computer account already exists. In such cases it will fail with the exception noted below. This is often the case when one is rebuilding/redeploying/etc an existing machine that uses a specific/static hostname.

With the changes in this PR, the process instead goes in this (IMO) more expected way:

  1. Renames computer to new hostname
  2. Joins computer to domain using new hostname (using the existing computer account if one is present)
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

membership

ADDITIONAL INFORMATION

Failure encountered when computer account already exists (line numbers per module version 1.4.1):

Computer 'IP-C0A8C10B' was successfully joined to the new domain 'XYZ.com', but renaming it to 'wsdev-s1-1' failed with the following error message: The account already exists.
At line:210 char:13
+             Add-Computer @joinParams
+             ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (IP-C0A8C10B:String) [Add-Computer], InvalidOperationException
    + FullyQualifiedErrorId : FailToRenameAfterJoinDomain,Microsoft.PowerShell.Commands.AddComputerCommand

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 210

The process I implemented is mentioned in the Add-Computer documentation for the JoinWithNewName Option here

This option is designed to be used with the Rename-Computer cmdlet. If you use the Rename-Computer cmdlet to rename the computer, but do not restart the computer to make the change effective, you can use this parameter to join the computer to a domain with its new name.


Copy link

Copy link
Collaborator

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes and fixing this problem. Also appreciate the info you shared about the problem, it was very helpful in understanding what was going on.

I've pushed a commit that added a changelog fragment and also some integration tests I added to verify the changes you've made here.

Copy link

@jborean93 jborean93 merged commit c510555 into ansible-collections:main Aug 21, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants