Chef-Metal/Provisioning input from multiple json files?


#1

I was trying to use chef-metal (now called chef provisioning I guess) to
deploy and destroy instances from a single rb file for multiple
environments. I can pass in the environmental data with a json file, but
the action, ie whether to start or stop the instance doesn’t belong in the
environment json file and it seems that I can’t pass two json files with
-j to the chef-client.

Eg, my recipe looks like this. There’s a case statement that starts or
stops the instance based on the value of node[‘action’]. I need to work out
how to get the node[‘action’] input into the file from somewhere… where?

#require 'chef_provisioning_fog’
require 'chef/provisioning/fog_driver’
require ‘chef/config’

with_chef_server “#{node[‘chef_server_url’]}”, {
:client_name => Chef::Config[:node_name],
:signing_key_filename => Chef::Config[:client_key]
}

case node[‘action’]
when 'create’
machine_batch do
machine “test01.#{node[‘env’]}.slicetest.com” do
chef_environment “#{node[‘env’]}“
role 'role-default’
converge true
machine_options :bootstrap_options => {
:flavor_id => ‘m1.large’,
:key_name => ‘test-ec2-default-v2’,
:groups => [‘slice-default’],
:image_id => ‘ami-226fd44a’,
:tags => {“env” =>
”#{node[‘env’]}”, ‘role’ => ‘default’ },
:iam_instance_profile_name => ‘instance-config’,
:availability_zone => “us-east-1a”,
:block_device_mapping => [
{ ‘DeviceName’ => ‘/dev/sdb’, ‘VirtualName’ =>
‘ephemeral0’ },
{ ‘DeviceName’ => ‘/dev/sdc’, ‘VirtualName’ =>
‘ephemeral1’ }
]
},
:ssh_username => ‘ec2-user’,
:use_private_ip_for_ssh => true
end
end
when 'destroy’
machine “test01.#{node[‘env’]}.slicetest.com” do
action :destroy
end
else
raise "Error"
end

Doug


#2

Maybe environment variables? Are you manually invoking chef-client?

case ENV[‘ACTION’]…. in the recipe
$ ACTION=destroy chef-client -j……

On Thursday, November 6, 2014 at 11:08 AM, Douglas Garstang wrote:

I was trying to use chef-metal (now called chef provisioning I guess) to deploy and destroy instances from a single rb file for multiple environments. I can pass in the environmental data with a json file, but the action, ie whether to start or stop the instance doesn’t belong in the environment json file and it seems that I can’t pass two json files with -j to the chef-client.

Eg, my recipe looks like this. There’s a case statement that starts or stops the instance based on the value of node[‘action’]. I need to work out how to get the node[‘action’] input into the file from somewhere… where?

#require 'chef_provisioning_fog’
require 'chef/provisioning/fog_driver’
require ‘chef/config’

with_chef_server “#{node[‘chef_server_url’]}”, {
:client_name => Chef::Config[:node_name],
:signing_key_filename => Chef::Config[:client_key]
}

case node[‘action’]
when 'create’
machine_batch do
machine “test01.#{node[‘env’]}.slicetest.com (http://slicetest.com)” do
chef_environment "#{node[‘env’]}"
role 'role-default’
converge true
machine_options :bootstrap_options => {
:flavor_id => ‘m1.large’,
:key_name => ‘test-ec2-default-v2’,
:groups => [‘slice-default’],
:image_id => ‘ami-226fd44a’,
:tags => {“env” => “#{node[‘env’]}”, ‘role’ => ‘default’ },
:iam_instance_profile_name => ‘instance-config’,
:availability_zone => “us-east-1a”,
:block_device_mapping => [
{ ‘DeviceName’ => ‘/dev/sdb’, ‘VirtualName’ => ‘ephemeral0’ },
{ ‘DeviceName’ => ‘/dev/sdc’, ‘VirtualName’ => ‘ephemeral1’ }
]
},
:ssh_username => ‘ec2-user’,
:use_private_ip_for_ssh => true
end
end
when 'destroy’
machine “test01.#{node[‘env’]}.slicetest.com (http://slicetest.com)” do
action :destroy
end
else
raise "Error"
end

Doug


#3

Thanks Daniel. That’s a possibility.

Doug.

On Thu, Nov 6, 2014 at 11:38 AM, Daniel Condomitti daniel@condomitti.com
wrote:

Maybe environment variables? Are you manually invoking chef-client?

case ENV[‘ACTION’]…. in the recipe
$ ACTION=destroy chef-client -j……

On Thursday, November 6, 2014 at 11:08 AM, Douglas Garstang wrote:

I was trying to use chef-metal (now called chef provisioning I guess) to
deploy and destroy instances from a single rb file for multiple
environments. I can pass in the environmental data with a json file, but
the action, ie whether to start or stop the instance doesn’t belong in the
environment json file and it seems that I can’t pass two json files with
-j to the chef-client.

Eg, my recipe looks like this. There’s a case statement that starts or
stops the instance based on the value of node[‘action’]. I need to work out
how to get the node[‘action’] input into the file from somewhere… where?

#require 'chef_provisioning_fog’
require 'chef/provisioning/fog_driver’
require ‘chef/config’

with_chef_server “#{node[‘chef_server_url’]}”, {
:client_name => Chef::Config[:node_name],
:signing_key_filename => Chef::Config[:client_key]
}

case node[‘action’]
when 'create’
machine_batch do
machine “test01.#{node[‘env’]}.slicetest.com” do
chef_environment “#{node[‘env’]}“
role 'role-default’
converge true
machine_options :bootstrap_options => {
:flavor_id => ‘m1.large’,
:key_name => ‘test-ec2-default-v2’,
:groups => [‘slice-default’],
:image_id => ‘ami-226fd44a’,
:tags => {“env” =>
”#{node[‘env’]}”, ‘role’ => ‘default’ },
:iam_instance_profile_name => ‘instance-config’,
:availability_zone => “us-east-1a”,
:block_device_mapping => [
{ ‘DeviceName’ => ‘/dev/sdb’, ‘VirtualName’ =>
‘ephemeral0’ },
{ ‘DeviceName’ => ‘/dev/sdc’, ‘VirtualName’ =>
‘ephemeral1’ }
]
},
:ssh_username => ‘ec2-user’,
:use_private_ip_for_ssh => true
end
end
when 'destroy’
machine “test01.#{node[‘env’]}.slicetest.com” do
action :destroy
end
else
raise "Error"
end

Doug


Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


#4

Except… it seems that ENV doesn’t work …

On Thu, Nov 6, 2014 at 11:46 AM, Douglas Garstang doug.garstang@gmail.com
wrote:

Thanks Daniel. That’s a possibility.

Doug.

On Thu, Nov 6, 2014 at 11:38 AM, Daniel Condomitti daniel@condomitti.com
wrote:

Maybe environment variables? Are you manually invoking chef-client?

case ENV[‘ACTION’]…. in the recipe
$ ACTION=destroy chef-client -j……

On Thursday, November 6, 2014 at 11:08 AM, Douglas Garstang wrote:

I was trying to use chef-metal (now called chef provisioning I guess) to
deploy and destroy instances from a single rb file for multiple
environments. I can pass in the environmental data with a json file, but
the action, ie whether to start or stop the instance doesn’t belong in the
environment json file and it seems that I can’t pass two json files with
-j to the chef-client.

Eg, my recipe looks like this. There’s a case statement that starts or
stops the instance based on the value of node[‘action’]. I need to work out
how to get the node[‘action’] input into the file from somewhere… where?

#require 'chef_provisioning_fog’
require 'chef/provisioning/fog_driver’
require ‘chef/config’

with_chef_server “#{node[‘chef_server_url’]}”, {
:client_name => Chef::Config[:node_name],
:signing_key_filename => Chef::Config[:client_key]
}

case node[‘action’]
when 'create’
machine_batch do
machine “test01.#{node[‘env’]}.slicetest.com” do
chef_environment “#{node[‘env’]}“
role 'role-default’
converge true
machine_options :bootstrap_options => {
:flavor_id => ‘m1.large’,
:key_name => ‘test-ec2-default-v2’,
:groups => [‘slice-default’],
:image_id => ‘ami-226fd44a’,
:tags => {“env” =>
”#{node[‘env’]}”, ‘role’ => ‘default’ },
:iam_instance_profile_name => ‘instance-config’,
:availability_zone => “us-east-1a”,
:block_device_mapping => [
{ ‘DeviceName’ => ‘/dev/sdb’, ‘VirtualName’ =>
‘ephemeral0’ },
{ ‘DeviceName’ => ‘/dev/sdc’, ‘VirtualName’ =>
‘ephemeral1’ }
]
},
:ssh_username => ‘ec2-user’,
:use_private_ip_for_ssh => true
end
end
when 'destroy’
machine “test01.#{node[‘env’]}.slicetest.com” do
action :destroy
end
else
raise "Error"
end

Doug


Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


#5

Yes it does. Ignore me.

On Thu, Nov 6, 2014 at 11:51 AM, Douglas Garstang doug.garstang@gmail.com
wrote:

Except… it seems that ENV doesn’t work …

On Thu, Nov 6, 2014 at 11:46 AM, Douglas Garstang <doug.garstang@gmail.com

wrote:

Thanks Daniel. That’s a possibility.

Doug.

On Thu, Nov 6, 2014 at 11:38 AM, Daniel Condomitti <daniel@condomitti.com

wrote:

Maybe environment variables? Are you manually invoking chef-client?

case ENV[‘ACTION’]…. in the recipe
$ ACTION=destroy chef-client -j……

On Thursday, November 6, 2014 at 11:08 AM, Douglas Garstang wrote:

I was trying to use chef-metal (now called chef provisioning I guess) to
deploy and destroy instances from a single rb file for multiple
environments. I can pass in the environmental data with a json file, but
the action, ie whether to start or stop the instance doesn’t belong in the
environment json file and it seems that I can’t pass two json files with
-j to the chef-client.

Eg, my recipe looks like this. There’s a case statement that starts or
stops the instance based on the value of node[‘action’]. I need to work out
how to get the node[‘action’] input into the file from somewhere… where?

#require 'chef_provisioning_fog’
require 'chef/provisioning/fog_driver’
require ‘chef/config’

with_chef_server “#{node[‘chef_server_url’]}”, {
:client_name => Chef::Config[:node_name],
:signing_key_filename => Chef::Config[:client_key]
}

case node[‘action’]
when 'create’
machine_batch do
machine “test01.#{node[‘env’]}.slicetest.com” do
chef_environment “#{node[‘env’]}“
role 'role-default’
converge true
machine_options :bootstrap_options => {
:flavor_id => ‘m1.large’,
:key_name => ‘test-ec2-default-v2’,
:groups => [‘slice-default’],
:image_id => ‘ami-226fd44a’,
:tags => {“env” =>
”#{node[‘env’]}”, ‘role’ => ‘default’ },
:iam_instance_profile_name => ‘instance-config’,
:availability_zone => “us-east-1a”,
:block_device_mapping => [
{ ‘DeviceName’ => ‘/dev/sdb’, ‘VirtualName’ =>
‘ephemeral0’ },
{ ‘DeviceName’ => ‘/dev/sdc’, ‘VirtualName’ =>
‘ephemeral1’ }
]
},
:ssh_username => ‘ec2-user’,
:use_private_ip_for_ssh => true
end
end
when 'destroy’
machine “test01.#{node[‘env’]}.slicetest.com” do
action :destroy
end
else
raise "Error"
end

Doug


Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627


Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627