Managing custom apache configs chef


#1

Hi List,
Is it possible to do the following with Chef and an httpd.conf file.
Here is my logic:

if environment_name (perhaps comes from a file on the system) == PRODUCTION
then sed -i s/LogLevel DEBUG/LogLevel INFO/
fi

So basically if a server meets some condition, then modify the file that is
being managed by chef.

Are there any example recipes/cookbooks to this point?

Thank you,
Z


#2

Are you using chef’s environments functionality or just wanting to
rely on a a file on the server?

I use Chef’s environments to dictate which data bag to use in some
situations - based on that logic you could call a bash function I
guess:

pull the data we need from the encrypted data bag

secrets_bag = "#{[node.chef_environment]}-secrets"
Chef::Log.info(“Based on the environment I’m using #{secrets_bag} as
the secrets data bag”)

There is probably a cleaner way to achieve your end result though -
you probably want something a little more programmatic in your
httpd.conf.erb template which check’s the environment and sets the
value based on that, rather than relying on bash / sed.

Wilb

On 15 August 2012 04:48, Zippy Zeppoli zippyzeppoli@gmail.com wrote:

Hi List,
Is it possible to do the following with Chef and an httpd.conf file.
Here is my logic:

if environment_name (perhaps comes from a file on the system) == PRODUCTION
then sed -i s/LogLevel DEBUG/LogLevel INFO/
fi

So basically if a server meets some condition, then modify the file that is
being managed by chef.

Are there any example recipes/cookbooks to this point?

Thank you,
Z


#3

You could also specify the data per environment in a data bag:

“log_level”: {
“production”: “debug”,
“development”: “info”
}

cjs

On Aug 15, 2012, at 3:01 AM, Adam Wilbraham mail@wilb.co.uk wrote:

Are you using chef’s environments functionality or just wanting to
rely on a a file on the server?

I use Chef’s environments to dictate which data bag to use in some
situations - based on that logic you could call a bash function I
guess:

pull the data we need from the encrypted data bag

secrets_bag = "#{[node.chef_environment]}-secrets"
Chef::Log.info(“Based on the environment I’m using #{secrets_bag} as
the secrets data bag”)

There is probably a cleaner way to achieve your end result though -
you probably want something a little more programmatic in your
httpd.conf.erb template which check’s the environment and sets the
value based on that, rather than relying on bash / sed.

Wilb

On 15 August 2012 04:48, Zippy Zeppoli zippyzeppoli@gmail.com wrote:

Hi List,
Is it possible to do the following with Chef and an httpd.conf file.
Here is my logic:

if environment_name (perhaps comes from a file on the system) == PRODUCTION
then sed -i s/LogLevel DEBUG/LogLevel INFO/
fi

So basically if a server meets some condition, then modify the file that is
being managed by chef.

Are there any example recipes/cookbooks to this point?

Thank you,
Z


#4

On Tue, Aug 14, 2012 at 11:48 PM, Zippy Zeppoli zippyzeppoli@gmail.com wrote:

Is it possible to do the following with Chef and an httpd.conf file.
Here is my logic:

if environment_name (perhaps comes from a file on the system) == PRODUCTION
then sed -i s/LogLevel DEBUG/LogLevel INFO/
fi

You should definitely do this in a template rather than using sed.

So basically if a server meets some condition, then modify the file that is
being managed by chef.

Are there any example recipes/cookbooks to this point?

There are many recipes that use node.chef_environment, which retrieves
the current environment you have configured in chef. Before the
environments feature, folks often used a databag for this information.

To do exactly what you’d want, you’d modify the apache2.conf.erb
template in the apache2 cookbook like so:

<% if node.chef_environment == “production” -%>
LogLevel INFO
<% else -%>
LogLevel DEBUG
<% end -%>

Bryan