DscWorkshop
DscWorkshop copied to clipboard
Node environment is not determined
Problem description
The expression [x={ $File.Directory.BaseName } =] does not determine node environment.
Verbose logs
null
How to reproduce
# source/AllNodes/Stage/server1.yml
NodeName: '[x={ $Node.Name }=]'
Environment: '[x={ $File.Directory.BaseName } =]'
Role: Webserver
Description: '[x= "$($Node.Role) in $($Node.Environment)" =]'
Location: DataCenter
Expected behavior
ParentFolderName of node yml file is set as node environment.
Current behavior
Describing Node Definition Files
Context Testing for conflicts / duplicate data
[+] Should not have duplicate node names 10ms (2ms|8ms)
[+] 'server1.dev.de' has valid yaml 24ms (21ms|3ms)
[!] 'server1.dev.de' is in the right environment is skipped, because Environment for 'server1.dev.de' is either not set or like '[x=*' 32ms (29ms|3ms)
[+] Location of 'server1.dev.de' is 'DataCenter' and does exist 8ms (6ms|1ms)
[!] Environment of 'server1.dev.de' is '[x={ $File.Directory.BaseName } =]' and does exist is skipped, because Environment for 'server1.dev.de' is either not set or like '[x=*' 5ms (4ms|1ms)
[+] Role of 'server1.dev.de' is 'Webserver' and does exist 15ms (7ms|8ms)
[!] Baseline of 'server1.dev.de' is '' and does exist is skipped, because Baseline for 'server1.dev.de' is not set 5ms (4ms|1ms)
Suggested solution
null
Operating system the target node is running
OsName : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture : 64-bit
WindowsVersion : 2009
WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage : en-US
OsMuiLanguages : {en-US}
PowerShell version and build the target node is running
Name Value
---- -----
PSVersion 5.1.19041.3693
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.3693
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Module version used
null
What I see in the logs is an expected warning. Datum handlers are called after tests. How does the RSOP for this node looks like? Does the correct environment show up in the RSOP file? The datum handlers are called in the RSOP task.
The correct environment show up in the RSOP file. But Description: '[x= "$($Node.Role) in $($Node.Environment)" =]' becomes 'Description: server1.dev.de in '. The value of $Node.Environment is missing.
If i use no datum expression like Environment: 'Prod' in node yml file the test fails:
[-] Environment of 'Server1.dev.de' is 'Prod' and does exist 19ms (18ms|1ms) at $node.Environment -in $Environments | Should -BeTrue, C:\Users\Admin\Documents\Code\DSC Workshop\tests\ConfigData\ConfigData.Tests.ps1:165 at <ScriptBlock>, C:\Users\Admin\Documents\Code\DSC Workshop\tests\ConfigData\ConfigData.Tests.ps1:165 Expected $true, but got $false.
I see the issue but I am not sure why it happens. There was a problem with calculated values being used in other calculated values but I don't remember the details.
Interestingly, this works which uses two layers of calculated values for the description.
NodeName: '[x={ $Node.Name }=]'
Environment: '[x={ $File.Directory.BaseName } =]'
Role: FileServer
Description: '[x= "$($Node.Role) in $($Node.Var3)" =]'
Location: Frankfurt
Baseline: Server
Var1: fixedValue
Var2: '[x={ "dynamicValue" }=]'
Var3: '[x={ "$($Node.Var1) $($Node.Var2)" }=]'
I will debug this. For now, please assign a static value to the environment
Environment: Dev #'[x={ $File.Directory.BaseName } =]'