[RESOLVED] Adding Multiple Servers to an Environment at Bootstrap

We are in the process of bootstrapping a lot of servers but need a good way to add them to an environment. We are going to use SCCM for Windows and we have it working except for adding to environment. I believe I read some where you can add the environment to client.rb but not sure on the syntax. Also, is there a script that we can add to the package that runs on the node to add to an environment such as Dev?



You can use the -E option at bootstrap to specify which environment the machine is a part of

For example, if you have a ‘dev’ environment, use -E dev at bootstrap

knife bootstrap windows winrm -N web1 -x foo -P xxx -r "role[web-default]" -E dev

Thanks for the response but that is fine if I want to bootstrap one at a time. Isn’t there a file I can specify the environment so I can add 100 servers to an environment at once.

i dont think so, but you can use the command suggested by spuder and add it in a loop to bootstrap all the 100 nodes.

I was reading the documentation here: https://docs.chef.io/config_rb_client.html and under settings it has this:

The name of the environment.

Is this something different?

yes its different, the environment is defined in your cookbook, have a read at this doc https://docs.chef.io/environments.html

I believe the only way to bootstrap multiple nodes at the same time is to run the bootstrap command in a LOOP.
you could do something like this:
for n in host1 host2 host3; do knife bootstrap $n -x -sudo -x user -r role[myapp]; done

To be a bit pedantic, other approaches are possible, but nothing is provided out of the box as the implementation must be a bit custom.

When bootstrapping a lot of nodes and you have an existing management tool like SCCM, you can use that tool to install Chef Client and follow a process similar to an unattended install.

Docs on unattended installs are here: Bootstrap a Node

The important bit for this discussion is the -j option to Chef Client, which provides initial node data for that system. There's more docs about that here: Chef Infra Client (executable) (scroll to -j). In particular, content like this:

  "chef_environment": "pre-production"

Should do the trick.