About | FAQ | Help
Ask Your Question
0

mysql_version custom fact fails [closed]

asked 2016-11-14 12:06:31 -0500

evil_del gravatar image

Hi, I'm getting the following error when I run puppet agent:

Error: Facter: error while resolving custom fact "mysql_version": undefined method `[]' for nil:NilClass

Same error when I run Puppet:

$ sudo facter -p mysql_version
2016-11-14 17:51:58.168291 ERROR puppetlabs.facter - error while resolving custom fact "mysql_version": undefined method `[]' for nil:NilClass

This custom fact seems to assume an array and uses element [0]:

Facter.add("mysql_version") do
  setcode do
    mysql_ver = Facter::Util::Resolution.exec('mysql --version')
    if mysql_ver
        mysql_ver.match(/\d+\.\d+\.\d+/)[0]
    end
  end
end

But how can this output be an array?

$ sudo mysql --version
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by evil_del
close date 2016-11-14 14:30:22.426245

2 Answers

Sort by » oldest newest most voted
0

answered 2016-11-14 14:29:51 -0500

evil_del gravatar image

Sorry. this was my fault. Issue with sudo access. All good now. Thanks.

edit flag offensive delete link more

Comments

You really should post what the problem and solution was even if it was your fault. Other people might step into the same trap. I got the same error and avoided that by switching away from puppetlabs-mysql version 4.0.1 to 5.0.0.

thoredge gravatar imagethoredge ( 2017-12-07 04:21:37 -0500 )edit
0

answered 2016-11-14 13:47:46 -0500

haus gravatar image

Ruby's match method (https://ruby-doc.org/core-2.1.4/Regex...) returns a MatchData object (https://ruby-doc.org/core-2.2.0/Match...), which responds to [] calls like an array does. The error you are seeing means that there was no match, so the match call returned nil.

When I tried that regex against the version string you posted, it returned the expected response of 5.1.73.

irb(main):001:0> a = "mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1"
=> "mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1"
irb(main):002:0> a.match(/\d+\.\d+\.\d+/)
=> #<MatchData "5.1.73">
irb(main):003:0> a.match(/\d+\.\d+\.\d+/)[0]
=> "5.1.73"

So for some reason, facter isn't getting the same reponse to mysql --version as you are.

Can you paste the results of adding --debug to the facter call? sudo facter -p --debug mysql_version

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-14 12:06:31 -0500

Seen: 181 times

Last updated: Nov 14 '16