'parameterize' recipies

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be ‘idempotent’, you run it once it
does it’s thing, if you rerun and the ‘target’ has not changed it won’t do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server template, but I
want to be able to run the same recipe but have it create a virtual host at
foo.domain.com’, whose DocumentRoot is ‘/vhosts/foo’, etc based on somehow
passing in ‘foo’ to the cookbook.


Erich Oliphant

“There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance”
– Hippocrates of Cos

Yes Chef is idempotent given the same set of cookbooks, and
attributes. You can make a cookbook do something different by changing
the attributes.

For example take a look at the apache cookbook default recipe line 67:
http://github.com/opscode/cookbooks/blob/master/apache2/recipes/default.rb#L67

You'll notice that node[:apache][:dir] is evaluated to determine the
directory where sites-available, sites-enabled, mods-available,
mods-enabled will be created. If you wanted to you could change the
value of the apache[:dir] attribute to say /home/erich/apache2, which
would end up creating:

/home/erich/apache2/sites-available
/home/erich/apache2/sites-enabled
/home/erich/apache2/mods-available
/home/erich/apache2/mods-enabled

On Thu, Apr 8, 2010 at 12:47 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be 'idempotent', you run it once it
does it's thing, if you rerun and the 'target' has not changed it won't do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server template, but I
want to be able to run the same recipe but have it create a virtual host at
'foo.domain.com', whose DocumentRoot is '/vhosts/foo', etc based on somehow
passing in 'foo' to the cookbook.

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

Ok cool, so basically I'd use a script or something to update the attribute
then just rerun chef-client ?

On Thu, Apr 8, 2010 at 1:06 PM, Michael Hale mikehale@gmail.com wrote:

Yes Chef is idempotent given the same set of cookbooks, and
attributes. You can make a cookbook do something different by changing
the attributes.

For example take a look at the apache cookbook default recipe line 67:

http://github.com/opscode/cookbooks/blob/master/apache2/recipes/default.rb#L67

You'll notice that node[:apache][:dir] is evaluated to determine the
directory where sites-available, sites-enabled, mods-available,
mods-enabled will be created. If you wanted to you could change the
value of the apache[:dir] attribute to say /home/erich/apache2, which
would end up creating:

/home/erich/apache2/sites-available
/home/erich/apache2/sites-enabled
/home/erich/apache2/mods-available
/home/erich/apache2/mods-enabled

On Thu, Apr 8, 2010 at 12:47 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be 'idempotent', you run it once it
does it's thing, if you rerun and the 'target' has not changed it won't
do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server template,
but I
want to be able to run the same recipe but have it create a virtual host
at
'foo.domain.com', whose DocumentRoot is '/vhosts/foo', etc based on
somehow
passing in 'foo' to the cookbook.

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

The way that Chef encourages you do do this is to build up the list of
items you want (vhosts in your example) and let Chef no-op on the
items that are already in the desired state.

For example, have a look at:
http://wiki.opscode.com/display/chef/Libraries#Libraries-AdvancedLibraryUsage

HTH,
Dan DeLeo

On Thu, Apr 8, 2010 at 11:24 AM, erich oliphant
erich.oliphant@gmail.com wrote:

Ok cool, so basically I'd use a script or something to update the attribute
then just rerun chef-client ?

On Thu, Apr 8, 2010 at 1:06 PM, Michael Hale mikehale@gmail.com wrote:

Yes Chef is idempotent given the same set of cookbooks, and
attributes. You can make a cookbook do something different by changing
the attributes.

For example take a look at the apache cookbook default recipe line 67:

http://github.com/opscode/cookbooks/blob/master/apache2/recipes/default.rb#L67

You'll notice that node[:apache][:dir] is evaluated to determine the
directory where sites-available, sites-enabled, mods-available,
mods-enabled will be created. If you wanted to you could change the
value of the apache[:dir] attribute to say /home/erich/apache2, which
would end up creating:

/home/erich/apache2/sites-available
/home/erich/apache2/sites-enabled
/home/erich/apache2/mods-available
/home/erich/apache2/mods-enabled

On Thu, Apr 8, 2010 at 12:47 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be 'idempotent', you run it once it
does it's thing, if you rerun and the 'target' has not changed it won't
do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server template,
but I
want to be able to run the same recipe but have it create a virtual host
at
'foo.domain.com', whose DocumentRoot is '/vhosts/foo', etc based on
somehow
passing in 'foo' to the cookbook.

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

wouldnt this be a good use for a data bag and a recipe that builds vsites based on it?

On Apr 8, 2010, at 11:38 AM, Daniel DeLeo wrote:

The way that Chef encourages you do do this is to build up the list of
items you want (vhosts in your example) and let Chef no-op on the
items that are already in the desired state.

For example, have a look at:
http://wiki.opscode.com/display/chef/Libraries#Libraries-AdvancedLibraryUsage

HTH,
Dan DeLeo

On Thu, Apr 8, 2010 at 11:24 AM, erich oliphant
erich.oliphant@gmail.com wrote:

Ok cool, so basically I'd use a script or something to update the attribute
then just rerun chef-client ?

On Thu, Apr 8, 2010 at 1:06 PM, Michael Hale mikehale@gmail.com wrote:

Yes Chef is idempotent given the same set of cookbooks, and
attributes. You can make a cookbook do something different by changing
the attributes.

For example take a look at the apache cookbook default recipe line 67:

http://github.com/opscode/cookbooks/blob/master/apache2/recipes/default.rb#L67

You'll notice that node[:apache][:dir] is evaluated to determine the
directory where sites-available, sites-enabled, mods-available,
mods-enabled will be created. If you wanted to you could change the
value of the apache[:dir] attribute to say /home/erich/apache2, which
would end up creating:

/home/erich/apache2/sites-available
/home/erich/apache2/sites-enabled
/home/erich/apache2/mods-available
/home/erich/apache2/mods-enabled

On Thu, Apr 8, 2010 at 12:47 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be 'idempotent', you run it once it
does it's thing, if you rerun and the 'target' has not changed it won't
do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server template,
but I
want to be able to run the same recipe but have it create a virtual host
at
'foo.domain.com', whose DocumentRoot is '/vhosts/foo', etc based on
somehow
passing in 'foo' to the cookbook.

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

Ok that makes sense as the say 5 sites are my desired 'target state'. But
then how do I make 'cookbook X' run for each of the 5 configs ?

On Thu, Apr 8, 2010 at 2:38 PM, Daniel DeLeo dan@kallistec.com wrote:

The way that Chef encourages you do do this is to build up the list of
items you want (vhosts in your example) and let Chef no-op on the
items that are already in the desired state.

For example, have a look at:

http://wiki.opscode.com/display/chef/Libraries#Libraries-AdvancedLibraryUsage

HTH,
Dan DeLeo

On Thu, Apr 8, 2010 at 11:24 AM, erich oliphant
erich.oliphant@gmail.com wrote:

Ok cool, so basically I'd use a script or something to update the
attribute
then just rerun chef-client ?

On Thu, Apr 8, 2010 at 1:06 PM, Michael Hale mikehale@gmail.com wrote:

Yes Chef is idempotent given the same set of cookbooks, and
attributes. You can make a cookbook do something different by changing
the attributes.

For example take a look at the apache cookbook default recipe line 67:

http://github.com/opscode/cookbooks/blob/master/apache2/recipes/default.rb#L67

You'll notice that node[:apache][:dir] is evaluated to determine the
directory where sites-available, sites-enabled, mods-available,
mods-enabled will be created. If you wanted to you could change the
value of the apache[:dir] attribute to say /home/erich/apache2, which
would end up creating:

/home/erich/apache2/sites-available
/home/erich/apache2/sites-enabled
/home/erich/apache2/mods-available
/home/erich/apache2/mods-enabled

On Thu, Apr 8, 2010 at 12:47 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be 'idempotent', you run it once
it
does it's thing, if you rerun and the 'target' has not changed it
won't
do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server template,
but I
want to be able to run the same recipe but have it create a virtual
host
at
'foo.domain.com', whose DocumentRoot is '/vhosts/foo', etc based on
somehow
passing in 'foo' to the cookbook.

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former
begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

There are lots of ways to do this, but the general pattern is that
you're not running the same recipe 5 times with different data, but
you're running one recipe that loops over the 5 items.

The example at the very bottom of the libraries wiki page shows how
you would do this; instead of the ISP.vhosts part, you can use an
array of hashes from any data source (data bag is a good one if you
don't already have the data in a different data store).

HTH,
Dan DeLeo

On Thu, Apr 8, 2010 at 12:10 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Ok that makes sense as the say 5 sites are my desired 'target state'. But
then how do I make 'cookbook X' run for each of the 5 configs ?

On Thu, Apr 8, 2010 at 2:38 PM, Daniel DeLeo dan@kallistec.com wrote:

The way that Chef encourages you do do this is to build up the list of
items you want (vhosts in your example) and let Chef no-op on the
items that are already in the desired state.

For example, have a look at:

http://wiki.opscode.com/display/chef/Libraries#Libraries-AdvancedLibraryUsage

HTH,
Dan DeLeo

On Thu, Apr 8, 2010 at 11:24 AM, erich oliphant
erich.oliphant@gmail.com wrote:

Ok cool, so basically I'd use a script or something to update the
attribute
then just rerun chef-client ?

On Thu, Apr 8, 2010 at 1:06 PM, Michael Hale mikehale@gmail.com wrote:

Yes Chef is idempotent given the same set of cookbooks, and
attributes. You can make a cookbook do something different by changing
the attributes.

For example take a look at the apache cookbook default recipe line 67:

http://github.com/opscode/cookbooks/blob/master/apache2/recipes/default.rb#L67

You'll notice that node[:apache][:dir] is evaluated to determine the
directory where sites-available, sites-enabled, mods-available,
mods-enabled will be created. If you wanted to you could change the
value of the apache[:dir] attribute to say /home/erich/apache2, which
would end up creating:

/home/erich/apache2/sites-available
/home/erich/apache2/sites-enabled
/home/erich/apache2/mods-available
/home/erich/apache2/mods-enabled

On Thu, Apr 8, 2010 at 12:47 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be 'idempotent', you run it once
it
does it's thing, if you rerun and the 'target' has not changed it
won't
do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server
template,
but I
want to be able to run the same recipe but have it create a virtual
host
at
'foo.domain.com', whose DocumentRoot is '/vhosts/foo', etc based on
somehow
passing in 'foo' to the cookbook.

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former
begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

Ok that looks like exactly what I need. Gotta break out my Ruby book :slight_smile:
Thanks!

On Thu, Apr 8, 2010 at 3:20 PM, Daniel DeLeo dan@kallistec.com wrote:

There are lots of ways to do this, but the general pattern is that
you're not running the same recipe 5 times with different data, but
you're running one recipe that loops over the 5 items.

The example at the very bottom of the libraries wiki page shows how
you would do this; instead of the ISP.vhosts part, you can use an
array of hashes from any data source (data bag is a good one if you
don't already have the data in a different data store).

HTH,
Dan DeLeo

On Thu, Apr 8, 2010 at 12:10 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Ok that makes sense as the say 5 sites are my desired 'target state'.
But
then how do I make 'cookbook X' run for each of the 5 configs ?

On Thu, Apr 8, 2010 at 2:38 PM, Daniel DeLeo dan@kallistec.com wrote:

The way that Chef encourages you do do this is to build up the list of
items you want (vhosts in your example) and let Chef no-op on the
items that are already in the desired state.

For example, have a look at:

http://wiki.opscode.com/display/chef/Libraries#Libraries-AdvancedLibraryUsage

HTH,
Dan DeLeo

On Thu, Apr 8, 2010 at 11:24 AM, erich oliphant
erich.oliphant@gmail.com wrote:

Ok cool, so basically I'd use a script or something to update the
attribute
then just rerun chef-client ?

On Thu, Apr 8, 2010 at 1:06 PM, Michael Hale mikehale@gmail.com
wrote:

Yes Chef is idempotent given the same set of cookbooks, and
attributes. You can make a cookbook do something different by
changing
the attributes.

For example take a look at the apache cookbook default recipe line
67:

http://github.com/opscode/cookbooks/blob/master/apache2/recipes/default.rb#L67

You'll notice that node[:apache][:dir] is evaluated to determine the
directory where sites-available, sites-enabled, mods-available,
mods-enabled will be created. If you wanted to you could change the
value of the apache[:dir] attribute to say /home/erich/apache2, which
would end up creating:

/home/erich/apache2/sites-available
/home/erich/apache2/sites-enabled
/home/erich/apache2/mods-available
/home/erich/apache2/mods-enabled

On Thu, Apr 8, 2010 at 12:47 PM, erich oliphant
erich.oliphant@gmail.com wrote:

Hi,
I am new to chef, have been through the examples,etc and have quick
question. Running a recipe seems to be 'idempotent', you run it
once
it
does it's thing, if you rerun and the 'target' has not changed it
won't
do
anything. I am trying to understand how I can use chef for dynamic
provisioning. For instance, I have an apache virtual server
template,
but I
want to be able to run the same recipe but have it create a virtual
host
at
'foo.domain.com', whose DocumentRoot is '/vhosts/foo', etc based
on
somehow
passing in 'foo' to the cookbook.

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former
begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former
begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos

--
Erich Oliphant

"There are, in fact, two things, science and opinion, the former begets
knowledge, the latter ignorance"
-- Hippocrates of Cos