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?