# Simple command to get node info when logged in on node through SSH

**URL:** <https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108>\
**Category:** Chef Infra (archive)\
**Created:** [June 19, 2013, 7:28am UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108 "2013-06-19T07:28:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxime\_Brugidou](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/maxime_brugidou/32/55_2.png) [@Maxime\_Brugidou](https://discourse.chef.io/u/Maxime_Brugidou)\
**Post date:** [June 19, 2013, 7:28am UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108/1 "2013-06-19T07:28:38Z")

</div>

Ohai all,

This is a simple question, we have many many nodes with various names and  
we make the node name match the FQDN with a pretty standard naming  
convention.

However when logged in on a machine it is very very useful to know what’s  
its Chef state. Currently multiple possibilities:

- Use the motd cookbook that will give you some last run static info when  
you login
- Use a command like knife node show (hostname -f) -c /etc/chef/client.rb -u (hostname -f)

I like the command (because it’s very flexible) but I’d expect it to be  
simpler, I know i can do a simple alias, deploy a simple script on my nodes  
or anything, but this has to be something that other people need right ?

So if we go the knife way, here are my suggestions:

- Why not make knife look for a client.rb file in /etc/chef/client.rb if no  
configuration is available?
- Why do i have to specify the node\_name conf through -u option? it should  
be default if none available
- Why not make knife node show without arguments show the current node if  
any ?

Please enlighten me if you know a better way (or if you don’t care).

Cheers,  
Maxime

---

<div class="post-metadata">

**Author:** ![Chirag\_Jog](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/chirag_jog/32/450_2.png) [@Chirag\_Jog](https://discourse.chef.io/u/Chirag_Jog)\
**Post date:** [June 19, 2013, 7:49am UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108/2 "2013-06-19T07:49:43Z")

</div>

How about knife status : [knife status](http://docs.opscode.com/knife_status.html) ?  
That gives a status of all the nodes including most recent chef-client run.

Regards\*,\*  
_Chirag Jog_  
Chief Technology Officer,  
_Clogeny Technologies_ | [http://clogeny.com](http://clogeny.com)  
(M) 0091-9766619440 | Skype: chirag.jog

On Wed, Jun 19, 2013 at 12:58 PM, Maxime Brugidou \<[maxime.brugidou@gmail.com](mailto:maxime.brugidou@gmail.com)

> wrote:

> Ohai all,
> 
> This is a simple question, we have many many nodes with various names and  
> we make the node name match the FQDN with a pretty standard naming  
> convention.
> 
> However when logged in on a machine it is very very useful to know what's  
> its Chef state. Currently multiple possibilities:
> 
> - Use the motd cookbook that will give you some last run static info when  
> you login
> - Use a command like knife node show $(hostname -f) -c /etc/chef/client.rb  
> -u $(hostname -f)
> 
> I like the command (because it's very flexible) but I'd expect it to be  
> simpler, I know i can do a simple alias, deploy a simple script on my nodes  
> or anything, but this has to be something that other people need right ?
> 
> So if we go the knife way, here are my suggestions:
> 
> - Why not make knife look for a client.rb file in /etc/chef/client.rb if  
> no configuration is available?
> - Why do i have to specify the node\_name conf through -u option? it should  
> be default if none available
> - Why not make knife node show without arguments show the current node if  
> any ?
> 
> Please enlighten me if you know a better way (or if you don't care).
> 
> Cheers,  
> Maxime

---

<div class="post-metadata">

**Author:** ![Maxime\_Brugidou](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/maxime_brugidou/32/55_2.png) [@Maxime\_Brugidou](https://discourse.chef.io/u/Maxime_Brugidou)\
**Post date:** [June 20, 2013, 11:41am UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108/3 "2013-06-20T11:41:51Z")

</div>

Hi Chirag, knife status has the same problem than knife node show: it does  
not work "out of the box" when you are logged in on a node. You need to  
specify the client.rb config, the node name... etc.

The goal is to get the Chef data of the node you are currently logged in.

On Wed, Jun 19, 2013 at 9:49 AM, Chirag Jog [chirag@clogeny.com](mailto:chirag@clogeny.com) wrote:

> How about knife status : [knife status](http://docs.opscode.com/knife_status.html) ?  
> That gives a status of all the nodes including most recent chef-client  
> run.
> 
> Regards\*,\*  
> _Chirag Jog_  
> Chief Technology Officer,  
> _Clogeny Technologies_ | [http://clogeny.com](http://clogeny.com)  
> (M) 0091-9766619440 | Skype: chirag.jog
> 
> On Wed, Jun 19, 2013 at 12:58 PM, Maxime Brugidou \<  
> [maxime.brugidou@gmail.com](mailto:maxime.brugidou@gmail.com)\> wrote:
> 
> > Ohai all,
> > 
> > This is a simple question, we have many many nodes with various names and  
> > we make the node name match the FQDN with a pretty standard naming  
> > convention.
> > 
> > However when logged in on a machine it is very very useful to know what's  
> > its Chef state. Currently multiple possibilities:
> > 
> > - Use the motd cookbook that will give you some last run static info when  
> > you login
> > - Use a command like knife node show $(hostname -f) -c  
> > /etc/chef/client.rb -u $(hostname -f)
> > 
> > I like the command (because it's very flexible) but I'd expect it to be  
> > simpler, I know i can do a simple alias, deploy a simple script on my nodes  
> > or anything, but this has to be something that other people need right ?
> > 
> > So if we go the knife way, here are my suggestions:
> > 
> > - Why not make knife look for a client.rb file in /etc/chef/client.rb if  
> > no configuration is available?
> > - Why do i have to specify the node\_name conf through -u option? it  
> > should be default if none available
> > - Why not make knife node show without arguments show the current node if  
> > any ?
> > 
> > Please enlighten me if you know a better way (or if you don't care).
> > 
> > Cheers,  
> > Maxime

---

<div class="post-metadata">

**Author:** ![Bryan\_Stenson](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bryan_stenson/32/420_2.png) [@Bryan\_Stenson](https://discourse.chef.io/u/Bryan_Stenson)\
**Post date:** [June 20, 2013, 1:34pm UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108/4 "2013-06-20T13:34:15Z")

</div>

maybe grep the client.log file and put interesting things into your PS1....

not sure how informed you'd like to be. 🙂

On Thu, Jun 20, 2013 at 4:41 AM, Maxime Brugidou  
[maxime.brugidou@gmail.com](mailto:maxime.brugidou@gmail.com)wrote:

> Hi Chirag, knife status has the same problem than knife node show: it does  
> not work "out of the box" when you are logged in on a node. You need to  
> specify the client.rb config, the node name... etc.
> 
> The goal is to get the Chef data of the node you are currently logged in.
> 
> On Wed, Jun 19, 2013 at 9:49 AM, Chirag Jog [chirag@clogeny.com](mailto:chirag@clogeny.com) wrote:
> 
> > How about knife status : [knife status](http://docs.opscode.com/knife_status.html) ?  
> > That gives a status of all the nodes including most recent chef-client  
> > run.
> > 
> > Regards\*,\*  
> > _Chirag Jog_  
> > Chief Technology Officer,  
> > _Clogeny Technologies_ | [http://clogeny.com](http://clogeny.com)  
> > (M) 0091-9766619440 | Skype: chirag.jog
> > 
> > On Wed, Jun 19, 2013 at 12:58 PM, Maxime Brugidou \<  
> > [maxime.brugidou@gmail.com](mailto:maxime.brugidou@gmail.com)\> wrote:
> > 
> > > Ohai all,
> > > 
> > > This is a simple question, we have many many nodes with various names  
> > > and we make the node name match the FQDN with a pretty standard naming  
> > > convention.
> > > 
> > > However when logged in on a machine it is very very useful to know  
> > > what's its Chef state. Currently multiple possibilities:
> > > 
> > > - Use the motd cookbook that will give you some last run static info  
> > > when you login
> > > - Use a command like knife node show $(hostname -f) -c  
> > > /etc/chef/client.rb -u $(hostname -f)
> > > 
> > > I like the command (because it's very flexible) but I'd expect it to be  
> > > simpler, I know i can do a simple alias, deploy a simple script on my nodes  
> > > or anything, but this has to be something that other people need right ?
> > > 
> > > So if we go the knife way, here are my suggestions:
> > > 
> > > - Why not make knife look for a client.rb file in /etc/chef/client.rb if  
> > > no configuration is available?
> > > - Why do i have to specify the node\_name conf through -u option? it  
> > > should be default if none available
> > > - Why not make knife node show without arguments show the current node  
> > > if any ?
> > > 
> > > Please enlighten me if you know a better way (or if you don't care).
> > > 
> > > Cheers,  
> > > Maxime

---

<div class="post-metadata">

**Author:** ![Morgan\_Blackthorne](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/morgan_blackthorne/32/100_2.png) [@Morgan\_Blackthorne](https://discourse.chef.io/u/Morgan_Blackthorne)\
**Post date:** [June 20, 2013, 2:51pm UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108/5 "2013-06-20T14:51:58Z")

</div>

Thanks for this thread. I just added a script to /etc/update-motd.d with  
the following:

#!/bin/sh

echo "Chef information:"  
echo ""  
knife node show $(hostname -f) -c /etc/chef/client.rb -u $(hostname -f) -a  
chef\_environment -a run\_list  
echo ""

Works great!

--  
~_~ StormeRider ~_~

"Every world needs its heroes [...] They inspire us to be better than we  
are. And they protect from the darkness that's just around the corner."

(from Smallville Season 6x1: "Zod")

On why I hate the phrase "that's so lame"... [http://bit.ly/Ps3uSS](http://bit.ly/Ps3uSS)

On Thu, Jun 20, 2013 at 6:34 AM, Bryan Stenson [bryan.stenson@gmail.com](mailto:bryan.stenson@gmail.com)wrote:

> maybe grep the client.log file and put interesting things into your PS1....
> 
> not sure how informed you'd like to be. 🙂
> 
> On Thu, Jun 20, 2013 at 4:41 AM, Maxime Brugidou \<  
> [maxime.brugidou@gmail.com](mailto:maxime.brugidou@gmail.com)\> wrote:
> 
> > Hi Chirag, knife status has the same problem than knife node show: it  
> > does not work "out of the box" when you are logged in on a node. You need  
> > to specify the client.rb config, the node name... etc.
> > 
> > The goal is to get the Chef data of the node you are currently logged in.
> > 
> > On Wed, Jun 19, 2013 at 9:49 AM, Chirag Jog [chirag@clogeny.com](mailto:chirag@clogeny.com) wrote:
> > 
> > > How about knife status : [knife status](http://docs.opscode.com/knife_status.html) ?  
> > > That gives a status of all the nodes including most recent chef-client  
> > > run.
> > > 
> > > Regards\*,\*  
> > > _Chirag Jog_  
> > > Chief Technology Officer,  
> > > _Clogeny Technologies_ | [http://clogeny.com](http://clogeny.com)  
> > > (M) 0091-9766619440 | Skype: chirag.jog
> > > 
> > > On Wed, Jun 19, 2013 at 12:58 PM, Maxime Brugidou \<  
> > > [maxime.brugidou@gmail.com](mailto:maxime.brugidou@gmail.com)\> wrote:
> > > 
> > > > Ohai all,
> > > > 
> > > > This is a simple question, we have many many nodes with various names  
> > > > and we make the node name match the FQDN with a pretty standard naming  
> > > > convention.
> > > > 
> > > > However when logged in on a machine it is very very useful to know  
> > > > what's its Chef state. Currently multiple possibilities:
> > > > 
> > > > - Use the motd cookbook that will give you some last run static info  
> > > > when you login
> > > > - Use a command like knife node show $(hostname -f) -c  
> > > > /etc/chef/client.rb -u $(hostname -f)
> > > > 
> > > > I like the command (because it's very flexible) but I'd expect it to be  
> > > > simpler, I know i can do a simple alias, deploy a simple script on my nodes  
> > > > or anything, but this has to be something that other people need right ?
> > > > 
> > > > So if we go the knife way, here are my suggestions:
> > > > 
> > > > - Why not make knife look for a client.rb file in /etc/chef/client.rb  
> > > > if no configuration is available?
> > > > - Why do i have to specify the node\_name conf through -u option? it  
> > > > should be default if none available
> > > > - Why not make knife node show without arguments show the current node  
> > > > if any ?
> > > > 
> > > > Please enlighten me if you know a better way (or if you don't care).
> > > > 
> > > > Cheers,  
> > > > Maxime

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [June 20, 2013, 3:16pm UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108/6 "2013-06-20T15:16:09Z")

</div>

On Thursday, June 20, 2013 at 4:41 AM, Maxime Brugidou wrote:

> Hi Chirag, knife status has the same problem than knife node show: it does not work "out of the box" when you are logged in on a node. You need to specify the client.rb config, the node name... etc.
> 
> The goal is to get the Chef data of the node you are currently logged in.

You could write a `knife exec` script to do what you want. If you're using fqdn node names, you can just shell out to `hostname --fqdn` to get the info and then set it with Chef::Config[:node\_name] = output\_of\_hostname\_cmd

> **[knife exec](https://docs.chef.io/workstation/knife_exec/)**
>
> Use the knife exec subcommand to execute Ruby scripts in the context of a fully configured Chef Infra Client. Use this subcommand to run scripts that will only access Chef Infra Server one time (or otherwise infrequently) or any time that an...

--  
Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![BradKnowles](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bradknowles/32/99_2.png) [@BradKnowles](https://discourse.chef.io/u/BradKnowles)\
**Post date:** [June 20, 2013, 3:25pm UTC](https://discourse.chef.io/t/simple-command-to-get-node-info-when-logged-in-on-node-through-ssh/4108/7 "2013-06-20T15:25:35Z")

</div>

On Jun 20, 2013, at 5:41 AM, Maxime Brugidou [maxime.brugidou@gmail.com](mailto:maxime.brugidou@gmail.com) wrote:

> Hi Chirag, knife status has the same problem than knife node show: it does not work "out of the box" when you are logged in on a node. You need to specify the client.rb config, the node name... etc.
> 
> The goal is to get the Chef data of the node you are currently logged in.

Knife is a program meant to interact with the Chef server, to see what information it has cached from whenever the most recent chef-client run was on that particular node. It is a program that is meant to be run from your Chef Workstation, not from individual nodes themselves.

Using a cookbook to update the motd file as part of each chef-client run is a good idea.

--  
Brad Knowles [brad@shub-internet.org](mailto:brad@shub-internet.org)  
LinkedIn Profile: [http://tinyurl.com/y8kpxu](http://tinyurl.com/y8kpxu)
