How can I supply different bootstrap_options to a chef-provisioning machine?


I’ve been trying out chef-provisioning-aws to set up our machines, and it’s awesome, so thanks very much all who made that possible!

I’m trying to get to a point, however, where I can define each of the machines of a cluster, but give each one a different VPC subnet, so as to spread my clusters’s nodes across each of the availability zones for HA.

As far as I can tell, the only way to do that would be to have each one have an entire machine resource, with all of the bootstrap_options defined, which is not very DRY.

For the time being, I’ve done something like so:

  '1b' => 'xxxxxxxx',
  '1c' => 'xxxxxxxx',
  '1d' => 'xxxxxxxx'
}.each do |az, subnet_id|
  m = "stage-mesos-agent-#{az}-#{ { (Array('a'..'z') + Array(0..9)).sample }.join}"
  machine m do
    chef_environment 'stage'
    file '/etc/chef/encrypted_data_bag_secret', "#{ENV['HOME']}/.chef/encrypted_data_bag_secret"
    run_list [
      bootstrap_options: {
        image_id:    { |r| r[:type] == 'hvm:instance-store' }[:ami],
        instance_type:        'c3.4xlarge',
        key_name:             ENV['AWS_SSH_KEY'],
        subnet_id:            "subnet-#{subnet_id}",
        security_group_ids:   %w(stage-mesos-slave stage-default),
        iam_instance_profile: 'stage-singularity-executor'
      transport_address_location: :private_ip,
      aws_tags: {
        Env: 'stage',
        Type: 'infra',
        Operator: ENV['USER']

I feel as though there must be a better way to do this, that takes advantage of machine_batch or something similar.