dsccommunity / dsccommunity/NetworkingDsc

MSFT_HostsFile: Host entries that have multiple entries on a single line fail

Open
#421 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion
Dominant language
PowerShell
Stars
235
Forks
93
PR merge metrics
No merged PRs in 30d

Description

Details of the scenario you tried and the problem that is occurring

When defining multiple entries on a single line it will write them to the host file every time the LCM kicks off.

Line 233 -259 takes in account for multiple entries per line but then a compare happens later against that array and a string that was passed into the Get-HostEntry.

Suggested solution to the issue

Change line 368
FROM: if ($result.Host -eq $HostName)
TO: if ([string]$result.Host -eq HostName)

The DSC configuration that is used to reproduce the issue (as detailed as possible)
HostsFile "Test1"
            {
                HostName  = 'test-ocsp-responder testVM.lab.local'
                IPAddress = '192.168.1.50'
                Ensure    = 'Present'
            }
The operating system the target node is running
OsName               : Microsoft Windows Server 2012 R2 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 9600.19358.amd64fre.winblue_ltsb_escrow.190505-1600
OsLanguage           : en-US
OsMuiLanguages       : {en-US}
Version and build of PowerShell the target node is running
Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Version of the DSC module that was used ('dev' if using current dev branch)

6.1.0.0 The code for this issue looks the same.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the MSFT_HostsFile implementation and inspect lines 233-259, where multiple entries per line are handled, followed by the comparison around line 368. Reproduce the issue with the provided HostsFile configuration and verify that repeated LCM runs do not rewrite an unchanged host entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.