Skip to content

Instantly share code, notes, and snippets.

@atheiman
Last active June 13, 2016 18:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atheiman/772bd181990469301da5bef0b171f1c7 to your computer and use it in GitHub Desktop.
Save atheiman/772bd181990469301da5bef0b171f1c7 to your computer and use it in GitHub Desktop.

Messing around with knife exec

SEARCH='chef_environment:*dev*' knife exec partial_search.rb
# - name: node-a
#   hostname: node-a
#   fqdn: node-a.domain.net
#   ipaddress: 10.190.116.124
#   run_list:
#   - role[base_os]
#   - recipe[some_cookbook]
#   chef_environment: awesome_app_dev
#   tags:
#   - tag-1
#   - tag-3
# - name: node-b.domain.net
#   hostname: node-b
#   fqdn: node-b.domain.net
#   ipaddress: 10.190.115.7
#   run_list:
#   - role[base_os]
#   - recipe[another_cookbook::some_recipe]
#   chef_environment: cool_service_dev
#   tags:
#   - tag-2
require 'yaml'
q = ENV['SEARCH']
raise "Set environment variable 'SEARCH' to specify the search query!" unless q
partial = {
'name' => ['name'],
'hostname' => ['hostname'],
'fqdn' => ['fqdn'],
'ipaddress' => ['ipaddress'],
'run_list' => ['run_list'],
'chef_environment' => ['chef_environment'],
'tags' => ['tags'],
}
resp = api.post("search/node?q=#{q}", partial)
nodes = resp['rows'].map { |r| r['data'] }
puts nodes.to_yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment