Windows – Using Chef Solo to provision a Windows EC2 instance and bootstrap it

amazon ec2chefchef-soloprovisioningwindows

I'm trying to automate our CI process for a couple of .NET apps, and in a perfect world I'd like to spin up a Windows EC2 instance for each, bootstrap the instance to install Chef Solo and then execute a Chef recipe to install some dependencies and the packaged software itself.

However – I'm a novice and have no idea even if that is feasible let alone where to start 🙂

I'm fairly well versed with the command line tools for AWS so can spin up an AMI ok, but beyond that point I'm pretty stuck. I would like to avoid building a custom AMI with chef pre-installed as that takes a lot of the advantages away.

I think this is essentially what I need to do – but is (unsurprisingly) focused on Linux:

http://www.opinionatedprogrammer.com/2011/06/chef-solo-tutorial-managing-a-single-server-with-chef/

Does anyone have a link to someone who has done this or similar before? Or a better way of achieving what I'd like to do?

Any help appreciated.

Best Answer

Most Windows bootstrap resources are focused on Hosted Chef and using the knife-windows plugin.

However this should be possible with Chef solo.

If you're not building an AMI with chef-client on it then your first step is to get the Full Chef Windows installer on there.

Fortunately, as I recall, winrm is enabled by default on the Windows Amazon AMIs. Take a look here for a potential bootstrap solution : https://stackoverflow.com/a/13284313/2205881

You could bootstrap other stuff at the same time; like Ruby Windows Installer etc. In the same process grab your cookbooks, roles etc and kick off your Chef provisioning.

UPDATE

I've started doing this in a slightly different way, using a --user-data-file when creating the instance. This can be used with the AWS API, command-line-tools or simply pasted into the web interface when Launching the Instance.

I'm using Chocolatey, a package manager, to install chef-client.

<script>
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
cinst chef-client
</script>

Basically: <script> tells AWS's user data scripts we've got a batch file to process.
@powershell... (etc) is a command to install Chocolatey from it's docs.
cinst chef-client installs the chef-client package.

None of this requires any user input. User data is executed as a local administrator.

All Amazon AMIs run their user data on first boot (by default) and not on subsequent boots. So this is a very simple way to get chef-client in place without needing to connect to RDP or even obtain your Administrator password.

Related Topic