ansible-collections / microsoft.ad

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

Error: Skip computer 'x' with new name 'x' because the new name is the same as the current name. #113

Closed aristotelos closed 5 months ago

aristotelos commented 5 months ago
SUMMARY

The microsoft.ad.membership fails if the computer name is longer than 15 characters.

ISSUE TYPE
COMPONENT NAME

microsoft.ad.membership

ANSIBLE VERSION
2.9.27
COLLECTION VERSION
microsoft.ad:1.5.0
CONFIGURATION
OS / ENVIRONMENT

Windows 10.

STEPS TO REPRODUCE

Join a computer to a domain using the following task. Use a computer name that is longer than 15 characters:

    - name: Join AD domain
      microsoft.ad.membership:
        dns_domain_name: "test.local"
        domain_admin_user: "{{ domain_admin_user}}"
        domain_admin_password: "{{ domain_admin_password }}"
        hostname: "my-long-computer-name"
        state: "domain"
        reboot: true
EXPECTED RESULTS

The step should succeed without changes because of idempotency.

ACTUAL RESULTS
Run: [2024-04-24 22:56:39,277][INFO][CMD]: TASK [ad-joined : Join AD domain]  **********************************************
Run: [2024-04-24 22:56:42,784][INFO][CMD]: fatal: [workstation] FAILED! => {"changed": false, "msg": "Skip computer 'my-long-computer-name' with new name 'my-long-computer-name' because the new name is the same as the current name.", "reboot_required": false}
Run: [2024-04-24 22:56:42,785][INFO][CMD]:  to retry, use: --limit @/app/data/playbook.retry
aristotelos commented 5 months ago

This is probably because the membership script uses $env:COMPUTERNAME which returns a name truncated to 15 characters. A better alternative is [System.Net.Dns]::GetHostName() which seems to return the correct name.