Error: Could not retrieve local facts: undefined method `split' for [1, 2, 3, 4, 5]:Array

293 views
Skip to first unread message

Spriya

unread,
Oct 10, 2014, 10:39:05 AM10/10/14
to puppet...@googlegroups.com
Hi,

when i am trying to do puppet custom facts to split [1,2,3,4,5] to 
1
2
3
4
5

It is throwing me error:
Error: Could not retrieve local facts: undefined method `split' for [1, 2, 3, 4, 5]:Array


Here is my facts

require 'facter'

ary = [1,2,3,4,5]
ary.map { |i| "'" + i.to_s + "'"}.join(",")

#str = ""
ary.each do |i|
#id,val = row[i]
 val = ary.split ","
Facter.add("base") do
  setcode do
    i
end
end
end


Anyone, help me

Craig White

unread,
Oct 10, 2014, 1:38:41 PM10/10/14
to puppet...@googlegroups.com
split is a string function

your ary is an array as you defined it

This will give you ruby functions for the Array class


Craig

Spriya

unread,
Oct 10, 2014, 1:57:02 PM10/10/14
to puppet...@googlegroups.com
Hi,

require 'facter'

ary = [1,2,3,4,5]

ary.each do |numbers|
Facter.add("base") do
  setcode do
  "#{numbers} "
end
end
end

In the fact it is returning only 1 value. In the fact it is returning base = 1 only not returning 2 3 4

Help me

Craig White

unread,
Oct 10, 2014, 2:29:58 PM10/10/14
to puppet...@googlegroups.com
Facter is basically a hash. You would want to name each specific 'fact' with a unique name as it would have one value - hash is a key => value pair.

Spriya

unread,
Oct 10, 2014, 2:33:28 PM10/10/14
to puppet...@googlegroups.com
Are there any instructions how to do this kind of?. I dont know how to do it.

  help me

Spriya

unread,
Oct 10, 2014, 3:51:14 PM10/10/14
to puppet...@googlegroups.com
Hi,

I wrote it like this. But it is not loading base2 facts

require 'facter'

ary = [1,2,3,4,5]
#ary.map { |i| "'" + i.to_s + "'"}.join(",")

#str = ""
ary.each do |numbers|
#id,val = row[i]
 #val = ary.split ","
Facter.add("base") do
  setcode do
  "numbers = #{numbers} "
end
end
end

Facter.add("basevalue1") do
  setcode do
  "numbers =  #{numbers} "
end
end

It is not loading basevalue1 fact.

Felix Frank

unread,
Oct 10, 2014, 7:28:02 PM10/10/14
to puppet...@googlegroups.com
On 10/10/2014 07:57 PM, Spriya wrote:
> Hi,
>
> require 'facter'
>
> ary = [1,2,3,4,5]
>
> ary.each do |numbers|
> Facter.add("base") do
> setcode do
> "#{numbers} "
> end
> end
> end
>
> In the fact it is returning only 1 value. In the fact it is returning
> base = 1 only not returning 2 3 4

First off, this description is way too vague to even start guessing
where you are going with this. It would be helpful if you can describe
what you are trying to solve in the long run.

Anyway, here is what I think you may want. Perhaps.

ary.each do |num|
Facter.add("base#{num}") do
setcode { num.to_s }
end
end

You get five facts, with the value equal to the respective index.

HTH,
Felix

Spriya

unread,
Oct 12, 2014, 3:31:42 PM10/12/14
to puppet...@googlegroups.com
Thank you flex for your suggestions
Reply all
Reply to author
Forward
0 new messages