0

Foreman Version 1.6.3

When I try to edit one of my hosts - change hostgroup - I get the following error:

ActiveRecord::RecordInvalid
Validation failed: Match has already been taken
app/models/concerns/host_common.rb:48:in `block in lookup_values_attributes='
app/models/concerns/host_common.rb:41:in `each_value'
app/models/concerns/host_common.rb:41:in `lookup_values_attributes='
app/controllers/hosts_controller.rb:113:in `block in update'
app/models/taxonomy.rb:52:in `block in no_taxonomy_scope'
app/models/taxonomy.rb:59:in `block (2 levels) in as_taxonomy'
app/models/concerns/foreman/thread_session.rb:148:in `as_location'
app/models/taxonomy.rb:58:in `block in as_taxonomy'
app/models/concerns/foreman/thread_session.rb:113:in `as_org'
app/models/taxonomy.rb:57:in `as_taxonomy'
app/models/taxonomy.rb:51:in `no_taxonomy_scope'
app/controllers/hosts_controller.rb:105:in `update'
app/models/concerns/foreman/thread_session.rb:33:in `clear_thread'
lib/middleware/catch_json_parse_errors.rb:9:in `call' 

production.log:

Started PUT "/hosts/puppet-app01" for 10.10.10.24 at 2015-03-05 11:51:32 +0100
Processing by HostsController#update as */*
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"/IYvSEW5JWu2dasdadL1Z/6fpjeMLojOFc0I+BIfY=", "host"=>{"name"=>"puppet-app01", "hostgroup_id"=>"", "environment_id"=>"7", "puppet_ca_proxy_id"=>"1", "puppet_proxy_id"=>"2", "config_group_ids"=>[""], "puppetclass_ids"=>["", "339", "293", "348", "349"], "managed"=>"f", "progress_report_id"=>"[FILTERED]", "lookup_values_attributes"=>"[FILTERED]", "is_owned_by"=>"5-Users", "enabled"=>"1", "comment"=>"", "overwrite"=>"false"}, "id"=>"puppet-app01"}
Operation FAILED: Validation failed: Match has already been taken
  Rendered common/500.html.erb (3.7ms)
Completed 500 Internal Server Error in 25ms (Views: 4.3ms | ActiveRecord: 3.5ms)

I get the same error every time I try to edit any parameter on this host. It started to happen after I assigned a class and removed it from this host.

This is my production environment and must be fixed ASAP.

Any ideas?

SEB
  • 23
  • 4
  • Silly question, but in foreman, can you just delete the host and have puppet re-add it on the next, presumably manual, run? Manually add back any classes you need? Or if it's in a hostgroup, then the appropriate classes ought to be added there anyway... – jmp242 Mar 05 '15 at 19:42
  • This host acts as the Foreman and Puppet CA. Does it change anything in your answer to my silly question? :P – SEB Mar 06 '15 at 06:52
  • Sorry, I meant my question was silly, not your question... And that it was an "obvious" to me work-around, not knowing that the host in question was the foreman host. – jmp242 Mar 06 '15 at 13:35

1 Answers1

0

Now I'm more than sure my question wasn't silly at all and jmp242's comment was nothing else but a silly workaround proposition. No offence! :P Anyway, it was my own fault HOWEVER caused by a strange behavior of Foreman web interface.

I was setting 2 matchers on 3 params in a class for 2 hosts. I set the first one for both hosts, then second and third. When I went back to the first param just to see if everything is fine before I submit changes I found out that it is set only for one host and not both. So, what have I done? I've set it one more time :)

That was "my" mistake! I was debugging this case by comparing in debug mode the same request on two hosts, the bad one and the good one. I found out that on the bad one "validation" transaction begins and is being rollbacked. I run manually each select query that was executed and discovered that this one is giving me back 1 row instead of 0:

SELECT 1 AS one FROM "lookup_values" WHERE ("lookup_values"."match" = 'fqdn=puppet-app01' AND "lookup_values"."id" != 39 AND "lookup_values"."lookup_key_id" = 1153) LIMIT 1;

I checked what is what and that way found out that there was a conflict in class params. Anyway, when I go to Puppet classes - MyClass - Smart Class Parameters - MyParam, I see one matcher! Than I click on another param and go back to the first one - I see both :) Strange, isn't it!? :)

SEB
  • 23
  • 4