How to get knife to connect using the IP instead of hostname


#1

I’m using AWS with EC2 instances in a private subnet meaning they have no public facing IP/hostname. When I install and run chef-client on the node, it’s registered on the Chef Server using it’s private hostname and ip, e.g.

ip-10-0-5-56.ec2.internal
10.0.5.56

When I try to run knife ssh "role:web" "sudo chef-client" -x ubuntu -i key.pem from my local machine, it tries to connect to the nodes using the private hostname. This hostname doesn’t actually exist and it doesn’t connect. I would like knife to connect using the private ip instead. Is this possible?


#2

You can use the -a or --attribute switch for knife ssh. I believe giving that a value of ipaddress should use the ohai ipaddress to connect.


#3

Thanks @Matt_Wrock - I literally just typed knife help ssh and saw that. :flushed: