We currently use Chef on-premise and would like to extend it into our AWS environment for the creation of AMI images to be used in Auto Scaling Groups. We do not wish the Chef client to be running when these images are running in AWS.
At the end of a node’s bootstrap / first convergence run is it possible to then automatically delete the node from the Chef server and uninstall the Chef client?
It’s worth noting that chef-client won’t run automatically unless you install the service or set it to run from cron/scheduled tasks. If you want to ensure that the instance can’t connect to the Chef server, you could also remove /etc/chef/ (Linux) or C:\chef (Windows).
If you really want to uninstall the chef-client application, I think the chef-ingredient cookbook has resources available for that, but I’ve not tried it myself.
For removing the node from the Chef server, it’s not something we’ve tried from a recipe. It may be possible, the Node object has a destroy method which should let you destroy it, but I’m not sure how this will interact with the run. Instead of this, we’ve always just had a script running somewhere that deletes nodes that haven’t checked in within the last 24 hours.