ansible-collections / microsoft.ad

Ansible collection for Active Directory management
GNU General Public License v3.0
36 stars 19 forks source link

The system cannot find the file specified. #88

Closed marksie1988 closed 5 months ago

marksie1988 commented 5 months ago
SUMMARY

Trying to join a number of Windows server 2022 to a test domain and they all keep failing saying "the system cannot find the file specified.

ISSUE TYPE
COMPONENT NAME

microsoft.ad.membership

ANSIBLE VERSION
ansible 2.10.8
COLLECTION VERSION
Collection   Version
------------ -------
microsoft.ad 1.4.1
CONFIGURATION
DEFAULT_ROLES_PATH(env: ANSIBLE_ROLES_PATH) = ['/home/user/repos/lab/ansible/roles~']
HOST_KEY_CHECKING(/home/user/repos/lab/ansible/ansible.cfg) = False
OS / ENVIRONMENT

Server 2022

STEPS TO REPRODUCE

I am using the following play:

    - name: Join members to domain
      microsoft.ad.membership:
        dns_domain_name: "{{ dns_domain_name }}"
        domain_admin_user: "{{ domain_admin_user }}"
        domain_admin_password: "{{ domain_admin_password }}"
        domain_ou_path: "{{ domain_join_ou_path }}"
        state: domain
        reboot: true

with these groupvars:

dns_domain_name: "lab.com"
domain_netbios_name: "LAB"
domain_admin_user: "administrator@lab.com"
domain_admin_password: "mypassword"
domain_join_ou_path: "OU=Windows,OU=Servers,DC=lab,DC=com"
EXPECTED RESULTS

Servers should be joined to the domain

ACTUAL RESULTS
The full traceback is:
Computer 'sql-1' failed to join domain 'lab.com' from its current workgroup 'WORKGROUP' with following error message: The system cannot find the file specified.
At line:210 char:13
+             Add-Computer @joinParams
+             ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (sql-1:String) [Add-Computer], InvalidOperationException
    + FullyQualifiedErrorId : FailToJoinDomainFromWorkgroup,Microsoft.PowerShell.Commands.AddComputerCommand

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 210
fatal: [sql-1]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Computer 'sql-1' failed to join domain 'raxlab.com' from its current workgroup 'WORKGROUP' with following error message: The system cannot find the file specified."
}
jborean93 commented 5 months ago

Unfortunately as the error is happening inside Add-Computer we don't have much control over how/why it is failing. An older issue https://github.com/ansible/ansible/issues/57313 seemed to indicate the domain_ou_path may have been invalid in that scenario so this would be a good place to start investigation. Running the same command locally outside of Ansible might also help narrow down if it's a network logon problem or something else.

marksie1988 commented 5 months ago

I ran the command outside of ansible and In this instance it also seems that this was caused by the OU not existing as its a test lab, I have removed that and it works now.

Not sure if it would be a good idea to add a message if this error happens to warn users it could be an incorrect OU path?

jborean93 commented 5 months ago

It would be a nice idea except that it would require a fair bit of code to resolve the domain controller hostname to actually do the ldap queries. I’m not sure if there is a builtin Windows mechanism to do so outside of what Add-Computer does internally.

jborean93 commented 5 months ago

I've just merged https://github.com/ansible-collections/microsoft.ad/pull/92 which tries to catch this particular error and add on a note saying to check the domain_ou_path on a failure. Hopefully that should help others who come across this problem in the future.