Finding recently created hosts with Chef

Blog-S_Secure_100x385
by | |1 min read

When you utilize cloud resources as a commodity, it can sometimes be hard to differentiate between individual systems. While testing some Chef installations on EC2 instances I asked myself, “which of these instances registered with my Chef server did I create a few hours ago?”

I considered searching through nodes for attributes that ought to be unique to these test instances, like the run_list. But, then I remembered that the time of the last Ohai run is stored as an Unix time in the automatic attributes of a Chef node run.

[sourcecode]
$ date +%s
1324426395
$ date –date="-5 hours" +%s
1324408398
$ knife search node ‘ohai_time:[1324408398 TO 1324426395]’ -i
2 items found

i-b25c8ad0

i-1e5c8a7c
[/sourcecode]

Above, I generated two time values using the date command, one for the current time and one for five hours ago. Then I used these values to search through my nodes for those who have had a Chef run in the last five hours using a range search with knife. This returned two nodes, which was exactly what I was looking for.

Another time-saving feature of Chef that you didn’t know you even wanted until you find yourself needing it.

banner background
Ready to Get Started?

Fexible deployment options to suit your enterprise needs—SaaS for a fully managed cloud experience, and Self-Managed for on-premises control.

request a trial

Consult a Progress Expert

Request a consultation with a Progress Professional Services expert.

learn more

All Blogs