-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix setting Path for Windows #1876
Conversation
@alex-slynko-wonga, can you give an example recipe that exhibits bad behavior without this change and describe the resulting behavior? Also, is this a regression from a particular Chef release, or has this behavior always been present? |
@@ -33,7 +33,9 @@ def create_env | |||
end | |||
obj.variablevalue = @new_resource.value | |||
obj.put_ | |||
ENV[@new_resource.key_name] = @new_resource.value | |||
value = @new_resource.value | |||
value.gsub!(/%SystemRoot%/, ENV['SystemRoot']) if @new_resource.key_name.upcase == 'PATH' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically PATH
could be specified as lowercase path
, or mixed case, correct? So we'd need to handle that scenario. Same for %SystemRoot%
in the environment variable value. And there may be parts of the path that contain other environment variables (e.g. %systemdrive%
, %windir%
, %programfiles%
, etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that is why I check key_name.upcase
windows_path recipe uses 'Path' at the moment.
And as for other variables - can be done.
Hi @adamedx
That happens because in mixlib-shellout there is a search for executable candidates using ENV['PATH'] And this happened only with latest version. |
fixing tests for replacing multiple variables |
@alex-slynko-wonga very interesting. Can you see if reverting to an old version of the windows cookbook, 1.34.0, resolves this? We had some fun with 'path' due to a regression in Chef that was fixed in 11.14.6. |
@Adamex that breaks only 11.14.6 |
@adamedx happens with 11.14.2 and 11.14.6. |
Verified this is an issue. Ruby does not look like it expands the variables, and the new representation does not expand them for us. Our implementation needs to take care of this in https://github.com/opscode/chef/blob/master/lib/chef/provider/env/windows.rb If we want to get this out to people ASAP, we can patch this in the windows cookbook for the meantime. |
So it looks like mixlib-shellout has had this bug for > 2 years? https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/windows.rb#L290 It seems like that's the appropriate place to fix it? |
^^^ okay so it looks like that is incorrect, but it wasn't clear. the behavior in pry looks like it smells like somewhere in ruby there should be a function to do that %-variable expansion and we should try to reuse that if possible, also we can't possibly be the only people to run into this... (any relevant stackoverflow questions?) |
It looks like reading ENV['PATH'] in Ruby returns the same format as
But the data we get back from WmiLite has embedded variables:
And the problem is when we modify that and then save it to ENV['PATH']. If I set something like So I think fixing mixlib-shellout#which is probably a separate bug, and we do need to make sure we don't save these unexpanded variables back to ENV['PATH'] but I'm feeling that we need to do it without hardcoding a list of potential variable names. |
private | ||
|
||
def expand_path(path) | ||
system_vars = %w(HomeDrive HomePath ProgramFiles SystemDirectory SystemDrive SystemRoot Temp Tmp UserProfile WinDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need to limit to these
@adamedx still broken in 11.16 :( |
Indeed, just ran into this issue also. See #2016 for details. |
The fix that @jdmundrawala is working on in the windows cookbook should be released this week which will work around the bug: chef-boneyard/windows#112 Fixing this will close #2009 as well. I'm leaving it open as an "issue" for now since this is an individual pull request. |
ENV['PATH'] is broken after changing path in windows. It replaces Path in Ruby to path with system variables.
That leads to broken recipes that use executables in System32.
Variant 1 is proposed in this pull request is to replace all systemroot variables to new ones.
Variant 2 would be to change ENV['Path'] separately from changing actual path.