[chef] Delayed evaluation of machine_options


Chronological Thread 
  • From: Christine Draper < >
  • To:
  • Subject: [chef] Delayed evaluation of machine_options
  • Date: Sat, 31 Jan 2015 13:52:28 -0600

Hi,

I came up with this approach to delaying evaluation of machine_options until converge (when the dynamically assigned IDs are available). Wondering if there's a better way. In particular, I'd really like to keep AWS-specific logic out of my machine_setup recipe.

aws_provisioner_setup.rb:

# set up the static machine options
with_machine_options :bootstrap_options => {
  :key_name => 'test1_aws',
  :instance_type => 't1.micro',
  :associate_public_ip_address => true
}

aws_network_setup.rb:

# Creates vpc, subnet, security group

machine_setup.rb:

opts = self.current_machine_options
machine 'mytest' do
  action :destroy
  machine_options lazy {
    opts[:bootstrap_options][:subnet] = data_bag_item("aws_subnet", "provisioning-vpc-subnet-a")["subnet_id"]
    opts[:bootstrap_options][:security_group_ids] = data_bag_item("aws_security_groups", "provisioning-vpc-security-group")["security_group_id"]
    opts
  }
end

Regards,
Christine Draper


  • [chef] Delayed evaluation of machine_options, Christine Draper, 01/31/2015

Archive powered by MHonArc 2.6.16.

§