Has anyone done any work modeling rewrite rules or ajp proxies with Chef?
Here is what I have in mind for the apache rewrite rules. Store the
individual rules in data_bags and create them using an LWRP.
data_bag/front_end_rewrites/main_page.json
{
“source”: “http://www.example.com/*”,
“target”: “http://backend1.example.com/”,
“flags”: “P”
}
file: apache_proxy/recipes/default.rb
include_recipe "apache"
include_recipe “apache::mod_rewrite”
rules = data_bag_item(‘front_end_rewrites’)
rules.each do |source,target,flags|
apache_rewrite do
source source
target target
flags flags
end
end
Does anyone see any problems w/ this approach?
Since the apache cookbook currently uses definitions, should I create
a new definition for apache_rewrite or create an LWRP? I have the
impression that LWRPs are now preferred to definitions.
Modeling ajp rules would be significantly more complex than the apache
rewrite rules. I haven’t put much thought into them yet.
Bryan,
A couple of questions come to mind:
- what if you need several rules in a specific order? Should source, target and flags be within an array?
- how would you apply different rules to different front ends? Maybe add a roles key to the bag, and skip the entry unless the node has one of them?
IMHO an LWRP is the way to go for this. These days my personal rule of thumb is: LWRP for generic, very reusable pieces; definitions for higher-level functionality.
On Jan 9, 2012, at 7:38 AM, Bryan Berry bryan.berry@gmail.com wrote:
Has anyone done any work modeling rewrite rules or ajp proxies with Chef?
Here is what I have in mind for the apache rewrite rules. Store the
individual rules in data_bags and create them using an LWRP.
data_bag/front_end_rewrites/main_page.json
{
"source": "http://www.example.com/*",
"target": "http://backend1.example.com/",
"flags": "P"
}
file: apache_proxy/recipes/default.rb
include_recipe "apache"
include_recipe "apache::mod_rewrite"
rules = data_bag_item('front_end_rewrites')
rules.each do |source,target,flags|
apache_rewrite do
source source
target target
flags flags
end
end
Does anyone see any problems w/ this approach?
Since the apache cookbook currently uses definitions, should I create
a new definition for apache_rewrite or create an LWRP? I have the
impression that LWRPs are now preferred to definitions.
Modeling ajp rules would be significantly more complex than the apache
rewrite rules. I haven't put much thought into them yet.
great ideas Andrea, btw Auguri, buon anno 
- what if you need several rules in a specific order? Should source, target and flags be within an array?
yeah they should be
I thought about this more and should fit w/in the data_bag for an
application like we see w/ the application cookbook, rather than just
for rewrite rules.
file: data_bags/applications/my_esb.json
{
"rewrite_rules": [
. . .
]
}
This handles the case where rewrite rules for one application need to
be in order but not where the rewrite rules for one application need
to be process before another.
This strategy also doesn't tie the rules to a specific virtual host. I
need to put more thought into this.
On Mon, Jan 9, 2012 at 9:50 AM, Andrea Campi
andrea.campi@zephirworks.com wrote:
Bryan,
A couple of questions come to mind:
- what if you need several rules in a specific order? Should source, target and flags be within an array?
- how would you apply different rules to different front ends? Maybe add a roles key to the bag, and skip the entry unless the node has one of them?
IMHO an LWRP is the way to go for this. These days my personal rule of thumb is: LWRP for generic, very reusable pieces; definitions for higher-level functionality.
On Jan 9, 2012, at 7:38 AM, Bryan Berry bryan.berry@gmail.com wrote:
Has anyone done any work modeling rewrite rules or ajp proxies with Chef?
Here is what I have in mind for the apache rewrite rules. Store the
individual rules in data_bags and create them using an LWRP.
data_bag/front_end_rewrites/main_page.json
{
"source": "http://www.example.com/*",
"target": "http://backend1.example.com/",
"flags": "P"
}
file: apache_proxy/recipes/default.rb
include_recipe "apache"
include_recipe "apache::mod_rewrite"
rules = data_bag_item('front_end_rewrites')
rules.each do |source,target,flags|
apache_rewrite do
source source
target target
flags flags
end
end
Does anyone see any problems w/ this approach?
Since the apache cookbook currently uses definitions, should I create
a new definition for apache_rewrite or create an LWRP? I have the
impression that LWRPs are now preferred to definitions.
Modeling ajp rules would be significantly more complex than the apache
rewrite rules. I haven't put much thought into them yet.
On Mon, Jan 9, 2012 at 10:06 AM, Bryan Berry bryan.berry@gmail.com wrote:
great ideas Andrea, btw Auguri, buon anno 
Same to you 
- what if you need several rules in a specific order? Should source,
target and flags be within an array?
yeah they should be
I thought about this more and should fit w/in the data_bag for an
application like we see w/ the application cookbook, rather than just
for rewrite rules.
Makes sense.
file: data_bags/applications/my_esb.json
{
"rewrite_rules": [
. . .
]
}
This handles the case where rewrite rules for one application need to
be in order but not where the rewrite rules for one application need
to be process before another.
This strategy also doesn't tie the rules to a specific virtual host. I
need to put more thought into this.
Right. Well, from my POV both limitations are ok. I can't think of many
cases where they would be a problem for me—if they are, I would probably
need something custom anyway.