2

I'm working with Chef through Amazon Opsworks and need to provision and configure additional network interfaces for some of my servers, and I'm having trouble figuring out how to properly use the ifconfig chef resource. The primary problem is that I don't know the IP address for the interface at the time I'm writing the chef recipe. All the examples I've seen show the target IP address expressed as a constant string in the resource name like so:

ifconfig '10.0.0.1' do
 eth1
end

However, I am provisioning the network interface at time of the execution of the recipe, so I don't know beforehand what IP address the provisioned network interface will be assigned in within the local network (Amazon VPC). I've written a ruby_block resource that provisions the interface and gathers the assigned IP, but I get errors from the chef resource when I try to pass it to the ifconfig resource as the documentation seems to suggest I should. My code looks similar to the following:

ruby_block 'provision_and_get_IP' do
  # Inside the following function the AWS CLI is called to provision
  # a network interface and return the assigned IP address
  assigned_ip = provision_and_get_ip()
  node["my_attributes"]["assigned_ip"] = assigned_ip
end

ifconfig 'setup_interface' do
  device 'eth1'  
  target lazy { node["my_attributes"]["assigned_ip"] }
end

And I get an error that reads

[2016-03-30T19:15:21+00:00] ERROR: ifconfig[setup_interface] (my_cookbook::my_recipe line 66) had an error: Chef::Exceptions::Exec: ifconfig eth1 setup_interface returned 1, expected 0
---- Begin output of ifconfig eth1 setup_interface ----
STDOUT: STDERR: setup_interface: Unknown host
ifconfig: `--help' gives usage information.
---- End output of ifconfig eth1 setup_interface ----

The documentation for the ifconfig resource seemed to suggest that the target property just defaults to the name of the resource and that if I set it this would work, but that seems to not be the case. What am I doing wrong here?

1 Answer 1

1

I don't think you will be able to achieve much with ifconfig recipe here. When you request additional interface for your VM it is allocated by Amazon and I think addressing is managed by Amazon as well. Even if you are able to change IP address of your interface there is a good chance it will not be recognized and routed properly by Amazon.

One of the options is to use private static IP addresses that you actually know the address your interface will receive ahead of time. Another option would be to extract address of the new interface from metadata.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .