4

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.

Kieran Benton
  • 131
  • 1
  • 5
  • 16

2 Answers2

8

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.

rjocoleman
  • 645
  • 3
  • 7
  • Ok, that seems to give me the pieces but it sounds a little fragile? What about windows specifics like retrieving admin password and waiting for provisioning time? Any specific advice on setting up chef client as solo from powershell? – Kieran Benton Mar 27 '13 at 07:16
  • It's only fragile dependant on your implementation, as with anything. This is the way to do it without Hosted Chef. Your Windows specifics are all handled by AWS things like EC2Config and User Data (like the setting the password to a known value and kicking off bootstrap once booted) - take a look here: http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/UsingConfig_WinAMI.html – rjocoleman Mar 28 '13 at 02:20
1

An alternative is to simply pass in a "user data script" written in Powershell. You just create a text file similar to the following (hello.ps1):

< powershell >

#Code to download and install aplications goes here

< /powershell >

Then when you launch the instance, you simply pass in the userdata file:

ec2run --region "us-east-1" "$ami" `

    --group "$mygroup" `

    --subnet "$mySubnet" --instance-type  "m1.medium" `

    --key "$myKey" `

    --user-data-file "hello.ps1"

You can download your binaries from S3 and do your installations completely via the single PowerShell script. Here is some documentation from Amazon for your reference

Ameer Deen
  • 3,598
  • 4
  • 26
  • 27