Ask Your Question
0

puppet agent 3.8.7 on windows fails, error is "undefined method split", apparently in package_version.rb

asked 2017-08-08 04:54:01 -0600

Trengo gravatar image
 C:\>puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve local facts: undefined method `split' for nil:NilClass
Error: Failed to apply catalog: Could not retrieve local facts: undefined method `split' for nil:NilClass

    C:\>puppet agent -t --debug --trace --verbose
    ...
    Debug: Loading facts from C:/ProgramData/PuppetLabs/puppet/var/lib/facter/security_updates.rb
    Error: Could not retrieve local facts: undefined method `split' for nil:NilClass
    C:/ProgramData/PuppetLabs/puppet/var/lib/facter/package_version.rb:23:in `<top (required)>'

and in package_version.rb:

os = Facter.value(:operatingsystem)

case os
when 'RedHat', 'CentOS', 'OracleLinux'
    package_data = Facter::Core::Execution.exec('rpm --query --all  --qf "%{NAME}||%{VERSION}\n"')

when 'Debian', 'Ubuntu'
    package_data = Facter::Core::Execution.exec('dpkg -l | grep "^ii" | awk \'BEGIN {OFS = "||"} ; {print $2,$3}\'')

else
    package_data = Facter::Core::Execution.exec('rpm --query --all  --qf "%{NAME}||%{VERSION}\n"')

end

package_data.split("\n").each do |line|
    package_detail = line.split('||')
    package_name = 'package_' + package_detail[0]
    package_version = package_detail[1]

    Facter.add(package_name) do
        setcode do
            package_version
        end
    end
end

i understand package_data is empty, this is windows, but why doesn't it know of the split function? am i missing something here?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-08-09 05:25:36 -0600

fvoges gravatar image

You current case statement assumes that it's an RPM based OS by default. That's wrong, it should default to an empty string which will work with split.

case os
  when 'RedHat', 'CentOS', 'OracleLinux'
    package_data = Facter::Core::Execution.exec('rpm --query --all  --qf "%{NAME}||%{VERSION}\n"')
  when 'Debian', 'Ubuntu'
    package_data = Facter::Core::Execution.exec('dpkg -l | grep "^ii" | awk \'BEGIN {OFS = "||"} ; {print $2,$3}\'')
  else
    package_data = ""
end

The reason for that is that you can say that in Ruby everything is an object and each object has a set of methods. The split method is available with strings but not with (what I assume is) an error object being returned by Facter::Core::Execution.exec().

edit flag offensive delete link more

Comments

thank you for your insight. package_version.rb is distributed in puppet package... i didn't modify it. do i have to edit it to make it work on windows machines? by the way, how should i edit this? puppet will reset the file to the default when it runs...

Trengo gravatar imageTrengo ( 2017-08-09 05:38:43 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-08-08 04:54:01 -0600

Seen: 151 times

Last updated: Aug 09