13

knife ssh isn't finding my nodes. I know it should be able to because when I can search for them I find them

# knife search node name:*
2 items found

Node Name:   web_01
...

Node Name:   admin
...

However, when I run knife ssh (I'll show it with the 'debug' flag) I get

# knife ssh "node:*" "uptime" -VV
DEBUG: Using configuration from /root/.chef/knife.rb
DEBUG: Signing the request as dev
DEBUG: Sending HTTP Request via GET to ec2-xx-xx-xx-xx.compute-1.amazonaws.com:4000/search/node
FATAL: No nodes returned from search!

(yes the host is correct, I just censored it for the post).

I've tried modifying the QUERY parameter and always get the same results. I've tried:

  • node:*
  • role:*
  • *
  • *:*

Any ideas?

Max
  • 439
  • 1
  • 4
  • 12

5 Answers5

16

I figured it out. my nodes did not have an fqdn. I had to specify -a ipaddress. the error message was not helpful. I figured it out by debugging knife ssh code. there is also a bug that it does not read the attribute from the knife config file. I'm going to open up a ticket about the issue and perhaps submit a patch.

What I did to get past this was put the hostname of the chef node in my /etc/hosts file with a pointer to the IP address. For example:

10.3.3.100 chef-client.int

You could, of course, always put it into a DNS server as well, along with the rest of your nodes. That would completely solve the problem.

Max
  • 439
  • 1
  • 4
  • 12
  • 7
    To clarify for other readers, "`-a ipaddress`" is literal. It apparently tells `knife ssh` to connect by IP not FQDN. This behaviour is dumb - it should fallback this way by default. – Steve Bennett Jul 19 '12 at 02:24
  • @SteveBennett I agree that it should be default behavior. I see how my post can be confusing. Thanks for clarifying. – Max Jul 19 '12 at 05:55
4

Also, if -a ipaddress doesn't work, try -a cloud.public_ipv4

I was shown this solution after figuring out that knife ssh was trying to use internal IP addresses for my nodes and it took some asking in the chef IRC channel (#chef on irc.freenode.net) before someone named retr0h showed me this.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
jLi
  • 136
  • 5
  • amazing, thank you! @all if you're running ec2, and your instances have been created with public IP, but hostname is pointed to local one, use the following: `knife ssh 'name:mydc1*' interactive -a node.node_name` – Ilja Feb 12 '16 at 14:25
0

Try knife ssh "id:*" "uptime".

Remember that knife ssh essentially does a knife search node, so your query should be one that works on knife search node (i.e., knife search node "node:*" doesn't work). knife ssh "role:*" should also work, but only if your nodes have roles assigned to them. For that matter, your original knife search node "name:*" should also work once you repurpose the query for knife ssh. So, knife ssh "name:*" "uptime".

cjc
  • 24,533
  • 2
  • 49
  • 69
  • 1
    Thanks for the reply, but I bet "No nodes" for both id:* and name:* – Max Jan 04 '12 at 12:42
  • OK, that's bizarre (i.e., it works for me). I've occasionally had to kick chef-solr to get new objects to show up in search, but, if you're getting results from "knife search node", you should be getting the same node list being used by "knife ssh". I don't know where to look next if the results list are different. – cjc Jan 04 '12 at 12:49
0

Have you ever tried knife ssh "name:*" "uptime"?

I'm using chef 10.x and it works for me.

In my opinion, when using knife search [INDEX] [QUERY], the first parameter INDEX is used to specify type of the item to be queried. While using knife ssh command, it knows that you are tryting to search nodes, so all you have to do is specify the [QUERY] part, which is name:* in your case.

ley
  • 13
  • 3
0

I solved this by using ssh/config and connecting by the fqdn.

h4ck3rm1k3
  • 101
  • 2