Skip to content

[<package>]/ensure: ensure changed '<package version>' to 'false' when there is no newer choco package available. #382

@aloosnetmatch

Description

@aloosnetmatch

Describe the Bug

Running the puppet (openvox) agent connected to puppet 8 (openvox) server i get these messages during the puppet run.
Notice: /Stage[main]/Platform::Install::Choco_basic_soft/Package[putty.install]/ensure: ensure changed '0.83.0' to 'false' (noop)

Expected Behavior

Since this is the latest update for this package I expect the choco provider to do nothing.

It seems when you run the "choco.exe upgrade --noop putty.install -r" command, the command that the provider generates to check for newer versions , it returns a 3 value output, like
"package name | current version| version pinned "

C:\Windows\system32>choco.exe upgrade --noop putty.install -r
putty.install|0.83.0|false

When there is an update available it returns a 4 value output, like
"package name | current version| version available |version pinned "

C:\Windows\system32>choco.exe upgrade --noop treesizefree -r
treesizefree|4.6.3|4.8.1.1|false

That seems to be a issue in file
modules\chocolatey\lib\puppet\provider\package\chocolatey.rb where the "available version" is static configured to take the third value.

package_ver = values[2]

Original source code

  def latest
    package_ver = ''
    PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall
    begin
      execpipe(latestcmd) do |process|
        process.each_line do |line|
          line.chomp!
          next if line.empty?

          if compiled_choco?
            values = line.split('|')
              package_ver = values[2]
            end
            # -----------------------------------------------------------
            # original line was:
            package_ver = values[2]
          else
            # Example: ( latest        : 2013.08.19.155043 )
            values = line.split(':').map(&:strip).delete_if(&:empty?)
            package_ver = values[1]
          end
        end
      end
    rescue Puppet::ExecutionFailure
      return nil
    end

I updated the code to

  def latest
    package_ver = ''
    PuppetX::Chocolatey::ChocolateyCommon.set_env_chocolateyinstall
    begin
      execpipe(latestcmd) do |process|
        process.each_line do |line|
          line.chomp!
          next if line.empty?

          if compiled_choco?
            values = line.split('|')
            # -----------------------------------------------------------
            # -----------------------------------------------------------
            # i encountered the issue where the output of  "choco.exe upgrade --noop wget -r"
            # provides three 3 output values instead of the expected 4 
            # When you run choco upgrade --noop -r, the output format is:
            # Name | InstalledVersion | AvailableVersion | IsPinned
            #             
            # C:\Windows\system32>choco.exe upgrade --noop wget -r
            # Wget|1.21.4|false

            if values[2] == "false" || values[2] == "true" || values[2].nil?
              # No update available, or we hit the 'Pinned' column early
              package_ver = values[1]
            else 
              # An update exists in the second index
              package_ver = values[2]
            end
            # -----------------------------------------------------------
            # original line was:
            # package_ver = values[2]
            # -----------------------------------------------------------
            # -----------------------------------------------------------            
          else
            # Example: ( latest        : 2013.08.19.155043 )
            values = line.split(':').map(&:strip).delete_if(&:empty?)
            package_ver = values[1]
          end
        end
      end
    rescue Puppet::ExecutionFailure
      return nil
    end

can this be fixed in the code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions