PSDscResources
PSDscResources copied to clipboard
Environment: Multiple Path entries : a conflict was detected between resources [Environment]SetMySQLBinaryPathVariable and [Environment]PHPPathEnvironmentVariable
Fails because the name value must be 'Path' but this this is used as a unique key. Couldn't find any issues raised regarding this, still a problem in 2.6.0.0. Is the general accepted solution to use a custom Script resource?
Related: https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11088876-dsc-environment-resource-does-not-allow-duplicate https://powershell.org/forums/topic/why-are-the-resourcekey-combination-required-to-be-unique/
+1, this is really implemented poorly. You should definitely be able to set multiple path entries in one configuration.
The resource is built to handle your scenario like this.
If either path in Value
exist already it will not be added twice.
Environment AddTwoPaths
{
Name = "Path"
Ensure = "Present"
Path = $true
Value = "C:\test123;C:\test456"
}
To remove multiple paths.
Environment RemoveTwoPaths
{
Name = "Path"
Ensure = "Absent"
Path = $true
Value = "C:\test123;C:\test456"
}
I label this issue as documentation and help wanted so that the community can create an example and update the documentation for this.
I tried to improve the documentation in xPSDesiredStateConfiguration to address this issue, but haven't submitted a similar PR to this repository.
I don't exactly know how code moves from experimental resources to non-experimental resources, or if it does at all, but I'll submit similar changes to this repository if they won't make their way here otherwise. (@johlju I wonder if you have any advice for me in that regard?)
You can see this resource module and xPSDesiredStateConfiguration resource module as separate with there own "life cycle". As this resource module do not allow breaking changes, only bug fixes and accepted enhancements, code are not moved from xPSDesiredStateConfiguration here. Updates to this resource module must be done through PR's.
For this issue, please send in a PR and I ask @kwirkykat to review it.
The resource is built to handle your scenario like this.
If either path in
Value
exist already it will not be added twice.
That example from @johlju partially addresses the issue.
But, if I need to add one Value
to Name
, then remove a different Value
from Name
, it fails because Name
must be unique. Or, if, multiple included resources need to modify the same path, it will fail as well. It may not be possible to combine all of them into one resource.
@gwimpey the resource make sure that the environment variable Path (refer to example above) is in desired state, and the resource must be unique in the final compiled mof. The desired state is that it should always have a path present, or always have a path absent - not both. It Ensure is added as Key, then it would be possible to both remove one or more path, and add one or more path. The reason why this is not done here is because if the same path would be added to both resource instances (one with 'Present' and another with 'Absent') it would become a ping-pong behavior and the node will never be in desired state.
Example (assuming both Name and Enusre is key):
Environment AddPath
{
Name = "Path"
Ensure = "Present"
Path = $true
Value = "C:\test123"
}
Environment RemovePath
{
Name = "Path"
Ensure = "Absent"
Path = $true
Value = "C:\test123"
}
This configuration would never be in desired state.
A better solution would be to add two new properties AddValue
and RemoveValue
(and Value
is not allowed to be used when either AddValue
and RemoveValue
is used) that will be used to add and remove values from the Name
. But this change cannot be a breaking change (don't think so?), and must be approved. If it is not approved (or is a breaking change), the change can be done in xPSDesiredStateConfiguration.