Jira (PUP-10679) Unable to install Ruby gem on Windows with ensure and version range

0 views
Skip to first unread message

Matt Dainty (Jira)

unread,
Sep 28, 2020, 11:21:05 AM9/28/20
to puppe...@googlegroups.com
Matt Dainty created an issue
 
Puppet / Bug PUP-10679
Unable to install Ruby gem on Windows with ensure and version range
Issue Type: Bug Bug
Affects Versions: PUP 5.5.21
Assignee: Unassigned
Components: Types and Providers
Created: 2020/09/28 8:20 AM
Priority: Normal Normal
Reporter: Matt Dainty

Puppet Version: 5.5.21
Puppet Server Version: n/a
OS Name/Version: Windows 2012R2

The following example on Windows doesn't work:

 

package { 'sensu-plugins-puppet':
  ensure   => '>= 2.2.0',
  provider => gem,
  command  => 'C:\\opt\\sensu\\embedded\\bin\\gem.cmd',
}

(This would normally be using the sensuclassic_gem provider which essentially just sets command for you, I've reproduced it just using the core Puppet provider for simplicity).

 

This works on Linux fine (with an adjusted command).

Desired Behavior:

The package should be installed honouring the ensure value like it does on Linux.

Actual Behavior:

 

 

Error: Could not update: Execution of 'C:\opt\sensu\embedded\bin\gem.cmd install -v ">= 2.2.0" --no-document sensu-plugins-puppet' returned 1: The filename, directory name, or volume label syntax is incorrect.
Error: /Stage[main]/Main/Package[sensu-plugins-puppet]/ensure: change from 'absent' to '>= 2.2.0' failed: Could not update: Execution of 'C:\opt\sensu\embedded\bin\gem.cmd install -v ">= 2.2.0" --no-document sensu-plugins-puppet' returned 1:
The filename, directory name, or volume label syntax is incorrect.

 

If I change the ensure to just a specific version or 'present', etc. it works. If I run the command manually, it also works so it suggests something to do with the way Puppet is constructing the command internally on Windows, my hunch is the ">= 2.2.0" is causing the trouble.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Matt Dainty (Jira)

unread,
Sep 28, 2020, 11:44:05 AM9/28/20
to puppe...@googlegroups.com
Matt Dainty commented on Bug PUP-10679
 
Re: Unable to install Ruby gem on Windows with ensure and version range

It's this block that is causing the problem:

 

if Puppet.features.microsoft_windows?
  version = resource[:ensure]
  command_options << "-v" << %Q["#{version}"] if (! resource[:ensure].is_a? Symbol) and useversion
else
  command_options << "-v" << resource[:ensure] if (! resource[:ensure].is_a? Symbol) and useversion
end

 

For some reason the version string is treated differently on Windows and explicitly quoted. If I change the code to just use the same code as !Windows my test case works.

This change looks like it was introduced by PUP-6563.

Mihai Buzgau (Jira)

unread,
Sep 28, 2020, 11:51:05 AM9/28/20
to puppe...@googlegroups.com
Mihai Buzgau commented on Bug PUP-10679

Hi Matt Dainty

Can you try to remove the space from the ensure value? Something like this:

package { 'sensu-plugins-puppet':
  ensure   => '>= 2.2.0',
  provider => gem,
  command  => 'C:\\opt\\sensu\\embedded\\bin\\gem.cmd',
}

Matt Dainty (Jira)

unread,
Sep 28, 2020, 12:05:04 PM9/28/20
to puppe...@googlegroups.com
Matt Dainty commented on Bug PUP-10679

If I change my example to use '~> 2.2.0' for the ensure value as per PUP-6563 then that also explodes in the same way. If I revert the changes made by PUP-6563 then both the example in that ticket and my example start working.

This leads me to suspect that the way this command was issued on Windows has changed and the quoting is now no longer needed. It makes sense therefore to revert this change, so I'll file a PR.

Matt Dainty (Jira)

unread,
Sep 28, 2020, 12:16:04 PM9/28/20
to puppe...@googlegroups.com
Matt Dainty commented on Bug PUP-10679

Mihai Buzgau if I remove the space, I get this:

Error: Could not update: Execution of 'C:\opt\sensu\embedded\bin\gem.bat install -v "=>2.2.0" --no-document sensu-plugins-puppet' returned 1: ERROR: While executing gem ... (Gem::Requirement::BadRequirementError)
 Illformed requirement ["=>2.2.0"]
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/requirement.rb:105:in `parse'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/requirement.rb:135:in `block in initialize'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/requirement.rb:135:in `map!'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/requirement.rb:135:in `initialize'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/version_option.rb:55:in `new'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/version_option.rb:55:in `block in add_version_option'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:548:in `conv_arg'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:676:in `parse'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:1581:in `block in parse_in_order'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:1538:in `catch'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:1538:in `parse_in_order'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:1532:in `order!'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:1626:in `permute!'
 C:/opt/sensu/embedded/lib/ruby/2.4.0/optparse.rb:1648:in `parse!'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/command.rb:388:in `handle_options'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/command.rb:299:in `invoke_with_build_args'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/command_manager.rb:173:in `process_args'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/command_manager.rb:143:in `run'
 C:/opt/sensu/embedded/lib/ruby/site_ruby/2.4.0/rubygems/gem_runner.rb:59:in `run'
 C:/opt/sensu/embedded/bin/gem:21:in `<main>'

So it seems the space is required.

Matt Dainty (Jira)

unread,
Sep 28, 2020, 1:11:07 PM9/28/20
to puppe...@googlegroups.com
Matt Dainty commented on Bug PUP-10679

Here's a summary of tests with and without a space between the operator and the version:

Ensure 5.5.21 PUP-6563 reverted Comment
~>2.2.0 Windows seems to intercept the >2.2.0 and Gem only sees the ~ as a version
~> 2.2.0  
=>2.2.0 Gem requires a space regardless
=> 2.2.0  

There seems to be some secret Windows shell expansions that I'm not familiar with at play here.

Mihai Buzgau (Jira)

unread,
Sep 30, 2020, 5:38:03 AM9/30/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Sep 30, 2020, 5:39:04 AM9/30/20
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Oct 30, 2020, 1:19:03 AM10/30/20
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-10679
 
Re: Unable to install Ruby gem on Windows with ensure and version range

It’s probably the greater than character. It’s possible to escape special chars on windows using caret {}. Maybe try '>= 2.2.0^’. The gem provider should handle that but maybe that’ll work for now?

Reply all
Reply to author
Forward
0 new messages