Chef dynamic inventory like Ansible

ansiblechefchef-serverchef-solo

In Ansible, I can use a shell script to provide a list of hosts to be configured, in Chef, I knew Chef Server provide the similar features.

However, I don't want to install a heavy server to provide just this feature, are there any workaround so I can do similar thing in Chef like Ansible?

Best Answer

The key thing that chef server provides over chef solo is the search ability, which can find servers/nodes based on a given query.

I understand not wanting to host your own chef server to gain this functionality! There are a lot of moving parts to provide it, erlang and rabbitmq and...

Luckily chef zero, or chef-client's --local mode as it's now known as, supports search and acts like a mini server of its own, only temporary.

It can read from json node/environment/role files in the right directory structure and act as the API endpoint until the chef run completes.

Given this structure, in addition to using search in recipes to find other nodes, it's possible to use knife search --local 'role:web-server AND chef_environment:production' to list matched nodes as well as knife ssh --local 'role:web-server AND chef_environment: production' 'ssh_command' to execute commands across all servers.

So, whilst this isn't exactly an ansible style dynamic inventory system, you can do a lot of things with it.