Delete client with new line name

So it started because I was trying to get auto-scalable nodes for self-registration with the chef. In my client.rb file, I had the following:

 node_name "some_prefix-#{`hostname`}" 

the idea was that each node would have the same prefix, but a suffix based on the host name. Unfortunately, hostname returns a string with \n at the end of it. The chef happily allowed me to create this client, but he cannot get access to it in any way.

 knife client show some_prefix-myHostname knife client show "some_prefix-myHostname\n" knife client show "some_prefix-myHostname%0A" 

all three results in 404

 knife client list 

shows the client and the empty line of the new line after it.

I fixed my client.rb template, but I cannot get rid of the nodes that I created using a new line in my names. I tried using a knife, webui, and even manually using the Chef :: REST library in irb, but it all leads to 404.

Any ideas?

EDIT: I also tried knife client bulk delete , but that also fails. It appears that the REST library deactivates the URL and removes the new line before trying to send a request.

+5
source share
2 answers

You can try using the raw knife , which allows you to send requests directly to the Chef Server API

 knife raw /nodes/<node-name> knife raw delete -m /nodes/<node-name> 

This worked for me on a similar issue with an invalid role name.

+1
source

This is a known bug in the chef server. I could not verify this - on my current server version (12) an error is triggered:

 Chef::Exceptions::ValidationFailed: Option name value test\n does not match regular expression /^[\-[:alnum:]_\.]+$/ 

But you can use the chef-API to restore it manually, as described (in another way) in the error report above:

 chef > api.get("/clients").keys => ["acme-validator", "some_prefix-myHostname\n"] chef > api.put("/clients/some_prefix-myHostname\n", name: "some_prefix-myHostname"); nil => nil chef > api.get("/clients").keys => ["acme-validator", "some_prefix-myHostname"] 

I felt free to already reorder the operators and replace "foobar" with "some_prefix-myHostname".

I assume that using the API should allow you to manually remove the client:

 api.delete("/clients/some_prefix-myHostname\n") 
0
source

All Articles