Adding Windows nodes to Chef 12 - case sensitivity/hostname duplicates


#1

Hi -

We are adding Windows nodes to Chef and are running into some issues around case sensitivity.

The hostname portion of the server’s AD FQDN may or may not be uppercase.
If a Windows node has already been registered in Chef with the name MYSERVER.domain.com, someone can still accidentally add myserver.domain.com as a new node.

C:>knife search node “fqdn:servername* OR fqdn:SERVERNAME*”

2 items found

Node Name: servername.mydomain.com
Environment: ops
FQDN: SERVERNAME.mydomain.com
IP: 10.11.12.14
Run List: role[base-chef], role[base-baremetal]
Roles: base-chef, base-baremetal
Recipes: role_base-chef, role_base-baremetal
Platform: windows 6.1.7601
Tags: dba, mssql, group1

Node Name: SERVERNAME.mydomain.com
Environment: ops
FQDN: SERVERNAME.mydomain.com
IP: 10.11.12.13
Run List:
Roles:
Recipes:
Platform: windows 6.1.7601
Tags:

Is there a way to tell the server to block registration of a Windows platform node if any case matches an existing node? We can’t rely on people naming hosts consistently…since Windows is a case-insensitive OS, we need to assume that the hostname case will vary and not simply Rely Upon the Kindness Of Strangers Doing the Right Thing.

Thank you!
Paula, still very new at this.


#2

This is a problem that I’ve run into aswell

The ways to solve this:

  1. Open feature request to make chef case sensitive
  2. Use terraform or chef provisioning to manage all your nodes.

In the long run, if you have a lot of users spinning up vms with chef. It will be better to use chef-zero or test kitchen to make these short lived development machines. (unfortunately if the server must be joined to a domain, these solutions won’t work well. )

The short term solution I came up with for times when you want centrally managed servers that anyone can create, is to wrap the knife bootstrap command in a powershell script that checks if the node already exists. Here is an excerpt from my powershell script.

write-host "Checking for $GUESTNAME duplicates, please wait" -ForegroundColor Yellow
$nodelist = knife node list
foreach ($i in $nodelist)
{
    if  ($i -match "$GUESTNAME")
    {
        write-error -message "Host `"$GUESTNAME`" already exists!" -Category InvalidData
        $exitcode = 1
        ReportToInfluxDB $sw.elapsed.minutes $GUESTNAME $GUESTCPUS $GUESTMEMORY $HVCOMPUTERNAME $exitcode
        if ($Slackuser) { SlackNotify $sw.elapsed.minutes $GUESTNAME $Slackuser $SLACKROOM $HVCOMPUTERNAME $exitcode }
        exit $exitcode
    }
}

#3

Thanks for the super-speedy reply. I’ll keep poking around to see if I can come up with other options too!