2

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?

Ryan
  • 5,341
  • 21
  • 71
  • 87
  • Ansible calls it ["dynamic inventory"](http://docs.ansible.com/ansible/intro_dynamic_inventory.html). You can use practially any program/script [which returns JSON](http://docs.ansible.com/ansible/developing_inventory.html) as a source. – jscott Aug 15 '16 at 11:57
  • I knew Ansible can do it, what I want to know if the *Chef way* to do the similar thing? – Ryan Aug 20 '16 at 07:56
  • @Ryan How does the *Chef way* look like then? Also, what did you try in Ansible to make it work? – 030 Aug 21 '16 at 08:42
  • 1
    Your question assumes that people know chef and ansible. While it is possible you narrow the number of people that can answer you. you'd better explain how chef inventory work. – Baptiste Mille-Mathias Aug 21 '16 at 13:39

1 Answers1

1

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.

jedifans
  • 206
  • 1
  • 4