Open jkeiser opened 9 years ago
Does add_machine_options within the machine block either perform overloading the "bar" variable already defined?
I am actually looking for a way to overload machine_options => bootstrap_options => flavor_ref attribute. To have a default, defined with with_machine_options and overload to different, on the machine block.
Yep, should be fine. You should try it, obviously, because it's possible I'm misunderstanding what you want :)
Well, what's essential is recursive merge of hashes. Like the following example updating the image_ref
(not yet tested). My experience few days back was that :bootstrap_options => {}
will replace whole bootstrap_option hash.
machine 'ops.ci.lab' do
attribute %w(apt compile_time_update), true
chef_environment CHEF_ENV
# flavor m.small
#add_machine_options :bootstrap_options => { :flavor_ref => '7c438087-10d7-4688-ac01-48614c2af3ff'}
...
...
end
Yep if you use add machine options it will recursive merge.
@jkeiser Is there anyway to change this behavior? I'd be willing to bet most users expect add_machine_options
to override hash keys set in with_machine_options
. In fact, that just bit us. If we can't change the behavior for these existing methods is there a method we can add to achieve this behavior when needed?
For our use-case we assign the exact same iam_instance_profile
to 99% of our instances and only wish to change that for the 1%. Due to this behavior we have to set the iam_instance_profile
explicitly on all machine definitions.
Disregard this statement.
What happens if you set it to nil on those machines where you really don't want it set to anything?
There are ways, I just suspect this will look more like you want.
We don't want it unset. Rather set to another value. However that leads to the behavior you describe above.
What do you mean by your last comment?
I'm confused. Would you mind writing an example?
Maybe this is what needs to be clearer: hashes and arrays are merged, and primitive values like strings get replaced.
If you wanted to override the iam instance profile using add machine options, and its a string, I would expect ads machine options to override.
@jkeiser Please disregard my comments. My vision is apparently blurry - bar != baz
:smirk:
OK! Sounds like this might do what you need then?
@jkeiser so how do we make this work for bootstrap options?
(using the latest that bundle update got me for gem 'chef-provisioning', github: 'chef/chef-provisioning' and gem 'chef-provisioning-aws', github: 'chef/chef-provisioning-aws' from today)
this doesn't work -
require 'chef/provisioning'
require 'chef/provisioning/aws_driver'
with_driver 'aws'
with_machine_options({
:bootstrap_options => { :instance_type => 't2.micro' }
})
machine 'blah' do
add_machine_options :bootstrap_options => { subnet: "testvpc-us-west-2c" }
action :ready
end
Result is -
================================================================================
Error executing action `ready` on resource 'machine[blah]'
================================================================================
TypeError
---------
can't dup NilClass
Resource Declaration:
---------------------
# In /Users/draistrick/git/fanduel/chef-work/metal-test/test-add.rb
12: machine 'blah' do
13: add_machine_options :bootstrap_options => { subnet: "testvpc-us-west-2c" }
14: action :ready
15: end
Compiled Resource:
------------------
# Declared in /Users/draistrick/git/fanduel/chef-work/metal-test/test-add.rb:12:in `from_file'
machine("blah") do
action [:ready]
retries 0
retry_delay 2
default_guard_interpreter :default
chef_server {:chef_server_url=>"chefzero://localhost:8889", :options=>{:client_name=>"draistrick-macbook.local", :signing_key_filename=>nil, :api_version=>"0"}}
driver "aws"
machine_options #<Cheffish::MergedConfig:0x007ff172af32f8 @configs=[{:bootstrap_options=>{:subnet=>"testvpc-us-west-2c"}}, {:bootstrap_options=>{:instance_type=>"t2.micro"}}], @merge_arrays={}>
declared_type :machine
cookbook_name "@recipe_files"
recipe_name "/Users/draistrick/git/fanduel/chef-work/metal-test/test-add.rb"
end
Hi everybody. I just wanted to point out that this feature (which I like and use) still appears to be undocumented except for here. And that's the title of the issue. So I'm bumping the thread cause additional documentation on this (and much of chef provisioning) would be of great use.
Almost a year later. Still not documented.
I'm going to toss in a little bumperino to point out that it's still not documented (although I think chef kinda wants provisioning to go away)
You can do both of these things now:
And the machine_options for "blah" will be
{ foo: 1, bar: 2, baz: 3 }
.We should document the crap out of it somewhere. Probably on chef.io docs.