Ask Your Question
0

Facter Troubles : undefined method `get_name' for main:Object

asked 2014-11-24 14:17:12 -0500

skirk gravatar image

updated 2014-11-25 08:06:29 -0500

Recently while attempting to dabble with setting custom facts for use by Facter and Puppet, after numerous puppet runs with a node, I began to receive the following error:

puppet agent --verbose --no-daemonize --onetime --environment my_test_env

err: Could not run Puppet configuration client: Could not retrieve local facts: undefined method `get_name' for main:Object

The template I am using to add custom facts:

# Facts: my_auto_deployment facts
###############################################################################
#
# Initialize all facts using manifest and template
foo = []
<% @custom_facts.each do |fact|  %>
<%= fact %> = <%= @fact %>
<% end %>
<% @fact_deltas.each do |fact|  %>
<%= fact %> = "Not_Available"
<% end %>

# Adds a new fact to facter
def add_fact(fact)
  fact.chomp!
  Facter.add("custom_#{fact}") do
    setcode { fact }
  end
end

# Calculates the difference between foo and bar and saves as a fact
def calculate_deltas(fact)
  if foo == "Not_Available" || bar == "Not_Available"
    add_fact(fact)
  else
    if get_name(fact) == "baz"
      fact = foo - bar
    end
    if get_name(fact)  == "zar"
      fact = bar - foo
    end
    fact = fact.join(",")
    add_fact(fact)
  end
end

<% @custom_facts.each do |fact|  %>
if get_name(<%= fact %>) == "bar"
  <%= fact %> = <%= fact %>.join(",")
end
add_fact(<%= fact %>)
<% end %>

<% @fact_deltas.each do |fact|  %>
calculate_deltas(<%= fact %>)
<% end %>`

Running facter --version gives:

1.6.11

Running facter --debug --trace --puppet gives:

uid=504(x) gid=507(oinstall) groups=507(oinstall),501(x)
/usr/lib/ruby/site_ruby/1.8/facter/my_custom_facts.rb:91: undefined method `get_name' for main:Object (NoMethodError)
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load_file'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:43:in `load_all'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:38:in `each'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:38:in `load_all'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:35:in `each'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:35:in `load_all'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/collection.rb:72:in `fact'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/collection.rb:117:in `value'
        from /usr/lib/ruby/site_ruby/1.8/facter.rb:98:in `send'
        from /usr/lib/ruby/site_ruby/1.8/facter.rb:98:in `value'
        from /usr/lib/ruby/site_ruby/1.8/facter/alphavision_releases.rb:15
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load_file'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:43:in `load_all'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:38:in `each'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:38:in `load_all'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:35:in `each'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:35:in `load_all'
        from /usr/lib/ruby/site_ruby/1.8/facter/util/collection.rb:93:in `load_all'
        from /usr/lib/ruby/site_ruby/1.8/facter.rb:104 ...
(more)
edit retag flag offensive close merge delete

Comments

can you please attach the output of facter --version and facter --debug --trace --puppet

Stefan gravatar imageStefan ( 2014-11-24 19:54:38 -0500 )edit

@Stefan, seems like one of the methods I was using in my ruby script is the issue, I will try removing my custom facts file and see if that helps. Also added the erb template. I think my ruby mistake here was missing the word "Imagine" from this post: http://stackoverflow.com/a/61729

skirk gravatar imageskirk ( 2014-11-25 07:58:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-12-05 16:26:50 -0500

skirk gravatar image

Following @Stefan's advice helped me to debug this issue. MY own faulty ruby script was the culprit. Removing the ruby file allowed puppet to generate a new catalog.

edit flag offensive delete link more

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: 2014-11-24 14:06:36 -0500

Seen: 556 times

Last updated: Dec 05 '14