In our environment, all of the servers live behind a firewall and chef
registers their private IP as the ‘IP’ attribute of the node.
Unfortunately, our workstations are on a separate network, so we need to
use the external IPs to SSH into the server. We have been storing the
external IP as a tag attribute and manually running ssh foo@1.2.3.4 'sudo chef-client
, but this can be cumbersome when working with
multiple nodes.
I have been trying to get knife ssh
to read the ‘Tags’ attribute like
so:
knife ssh name:foo* ‘sudo chef-client’ -a ‘Tags’
The Tags variable appears to be an array, but no amount of fiddling with
the syntax has netted me the results I’m looking for. I even went so
far as to remove all of the tags except the IP, but that didn’t work
either.
Has anyone gotten this to work, and if so what sort of hocus pocus did
you do to create this magic?
Thanks,
Sheppy R
Wow, after many hours of trying 'Tags' I accidentally type it all lower
case and it magically works, but apparently only when the tag contains
only the public IP. So my follow up to this is how do I pull just one
of the tags when there are multiple?
Thanks again,
Sheppy
On Sat, 2014-07-26 at 02:17 +0000, Sheppy Reno wrote:
In our environment, all of the servers live behind a firewall and chef
registers their private IP as the 'IP' attribute of the node.
Unfortunately, our workstations are on a separate network, so we need to
use the external IPs to SSH into the server. We have been storing the
external IP as a tag attribute and manually running ssh foo@1.2.3.4 'sudo chef-client
, but this can be cumbersome when working with
multiple nodes.
I have been trying to get knife ssh
to read the 'Tags' attribute like
so:
knife ssh name:foo* 'sudo chef-client' -a 'Tags'
The Tags variable appears to be an array, but no amount of fiddling with
the syntax has netted me the results I'm looking for. I even went so
far as to remove all of the tags except the IP, but that didn't work
either.
Has anyone gotten this to work, and if so what sort of hocus pocus did
you do to create this magic?
Thanks,
Sheppy R
On Saturday, July 26, 2014 at 3:54 AM, Sheppy Reno wrote:
Wow, after many hours of trying 'Tags' I accidentally type it all lower
case and it magically works, but apparently only when the tag contains
only the public IP. So my follow up to this is how do I pull just one
of the tags when there are multiple?
Thanks again,
Sheppy
Tags are meant to be an Array of strings. There isn’t really an easy way to specify a path through a nested data structure that handles Arrays like you want. For example, suppose you add a new tag to some nodes, and for some reason the order isn’t the same on all nodes. Then you would have
node1[‘tags’] == [“1.2.3.4”, “my_new_tag”]
node2[‘tags’] == [“my_new_tag”, “2.3.4.5”]
Since you can only refer to array elements by position, there’s no way to pick a specific tag except by iterating over the elements and inspecting them.
I’d recommend making a custom attribute that’s a Hash instead. In your recipe code, do:
node.set[“external_ip”] = “1.2.3.4”
And with knife, use
knife ssh QUERY -a external_ip
HTH
--
Daniel DeLeo