- From:
- To: chef <
>
- Subject: [chef] defining a global variable to avoid sprinkles
- Date: Mon, 9 Jan 2012 12:40:54 -0800
i'm finding myself sprinkling my cookbooks with repeated code, and wondering
how i can do this differently. i'm in ec2. let's say i want to define
subdomains keyed off of 2 things: a userdata setting and
placement_availability_zone:
if userdata contains "-e dev" and av zone matches us-east-1, subdomain is
dev.abfabreunion.com.
if userdata contains "-e prod" and av zone matches us-east-1, subdomain is
prod.abfabreunion.com.
and so on.
i'd want to make that derived subdomain available to all of my cookbooks. is
there a way to do that in chef without sprinkling my code with the following?
mrepo/attributes/default.rb:
if node[:ec2][:userdata] =~ /-e dev/ &&
node[:ec2][:placement_availability_zone] =~ /us-east-1/
node.default[:mrepo][:smtpserver] = "mail1.dev.abfabreunion.com"
elsif node[:ec2][:userdata] =~ /-e prod/ &&
node[:ec2][:placement_availability_zone] =~ /us-east-1/
node.default[:mrepo][:smtpserver] = "mail1.prod.abfabreunion.com"
elsif node[:ec2][:userdata] =~ /-e prod/ &&
node[:ec2][:placement_availability_zone] =~ /us-west-2/
node.default[:mrepo][:smtpserver] = "mail1.prod2.abfabreunion.com"
end
openvpn/attributes/default.rb:
if node[:ec2][:userdata] =~ /-e dev/ &&
node[:ec2][:placement_availability_zone] =~ /us-east-1/
node.default[:openvpn][:dhcpdomain] = "dev.abfabreunion.com"
elsif node[:ec2][:userdata] =~ /-e prod/ &&
node[:ec2][:placement_availability_zone] =~ /us-east-1/
node.default[:openvpn][:dhcpdomain] = "prod.abfabreunion.com"
elsif node[:ec2][:userdata] =~ /-e prod/ &&
node[:ec2][:placement_availability_zone] =~ /us-west-2/
node.default[:openvpn][:dhcpdomain] = "prod2.abfabreunion.com"
end
and so on.
thanks,
kallen
- [chef] defining a global variable to avoid sprinkles, kallen, 01/09/2012
Archive powered by MHonArc 2.6.16.