Question about recipes


#1

I have a question about RPM:s and config files with chef.
Im sorry if im writing a question I should find the answer to on the
site but have not found any information regarding it or I could just
have missed it.

The question I have is. If I write a recipe that installs a RPM
package trough yum, then deploys config files in specific directories
and then restarts the enables and starts the service. Then have a
dependency on apache recipe and does and action [:restart] on httpd
service.

What does the chef recipe actualy do the second time chef runs? Does
it reinstalls the RPM and config files then restarts the httpd
service? Or does it do a diff to see if its the same package and skip
the installation and configfiles but restarts httpd?

Anyone who can enlighten me or point me to a RTFM page? =)

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT


#2

TL;DR - Chef will probably do nothing on the second run.

Actual answer -

Chef will parse the recipe, compiling a “resource collection” that
looks something like:

[ ‘package[apache]’, ‘file[yourconfig]’, ‘service[apache]’ ]

Then, it will process the resources individually, in the order
generated by the recipe. Each resource will independently check to see
if it needs to take action to fix its subject through a provider,
potentially changing the system as it goes.

The package resource will consult the package manager to test if it
needs to install apache.
Think if [rpm -qa | grep apache] of if [dpkg -L | grep apache]
under the hood.

The file resource (and its cousins template, remote_file,
cookbook_file, etc) will take checksums in memory and against the file
on disk. If they differ, the one in memory wins and gets written,
leaving you a diff in your output. (logs, why-run, etc)

‘service[apache]’ will check to see if apache is running and fix it if
it isn’t, etc.

hope that helps

-s

On Mon, Nov 5, 2012 at 9:02 AM, Jens Skott jens.skott@schibsted.se wrote:

I have a question about RPM:s and config files with chef.
Im sorry if im writing a question I should find the answer to on the
site but have not found any information regarding it or I could just
have missed it.

The question I have is. If I write a recipe that installs a RPM
package trough yum, then deploys config files in specific directories
and then restarts the enables and starts the service. Then have a
dependency on apache recipe and does and action [:restart] on httpd
service.

What does the chef recipe actualy do the second time chef runs? Does
it reinstalls the RPM and config files then restarts the httpd
service? Or does it do a diff to see if its the same package and skip
the installation and configfiles but restarts httpd?

Anyone who can enlighten me or point me to a RTFM page? =)

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT


#3

But if i put a action [:restart] will it restart it every time the
client parses the recipe?
If so do I have to put it in a not_if thingy to make it not restart if
there are stuff present?

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT

2012/11/5 Sean OMeara someara@gmail.com:

TL;DR - Chef will probably do nothing on the second run.

Actual answer -

Chef will parse the recipe, compiling a “resource collection” that
looks something like:

[ ‘package[apache]’, ‘file[yourconfig]’, ‘service[apache]’ ]

Then, it will process the resources individually, in the order
generated by the recipe. Each resource will independently check to see
if it needs to take action to fix its subject through a provider,
potentially changing the system as it goes.

The package resource will consult the package manager to test if it
needs to install apache.
Think if [rpm -qa | grep apache] of if [dpkg -L | grep apache]
under the hood.

The file resource (and its cousins template, remote_file,
cookbook_file, etc) will take checksums in memory and against the file
on disk. If they differ, the one in memory wins and gets written,
leaving you a diff in your output. (logs, why-run, etc)

‘service[apache]’ will check to see if apache is running and fix it if
it isn’t, etc.

hope that helps

-s

On Mon, Nov 5, 2012 at 9:02 AM, Jens Skott jens.skott@schibsted.se wrote:

I have a question about RPM:s and config files with chef.
Im sorry if im writing a question I should find the answer to on the
site but have not found any information regarding it or I could just
have missed it.

The question I have is. If I write a recipe that installs a RPM
package trough yum, then deploys config files in specific directories
and then restarts the enables and starts the service. Then have a
dependency on apache recipe and does and action [:restart] on httpd
service.

What does the chef recipe actualy do the second time chef runs? Does
it reinstalls the RPM and config files then restarts the httpd
service? Or does it do a diff to see if its the same package and skip
the installation and configfiles but restarts httpd?

Anyone who can enlighten me or point me to a RTFM page? =)

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT


#4

it will not run again the second time chef runs, most of resources are and
every time chef client runs, it will chef the resource status, if it is not
we expected(like package is not been installed), it will take the action to
bring that part to the status we expected, if it is already in the status
we expected(like package already installed), it will do nothing

about config file and service, you may want to use notifies, which mainly
means when config file changes, send some single(like restart) to the
service resource

hope this help

On Mon, Nov 5, 2012 at 10:02 PM, Jens Skott jens.skott@schibsted.se wrote:

I have a question about RPM:s and config files with chef.
Im sorry if im writing a question I should find the answer to on the
site but have not found any information regarding it or I could just
have missed it.

The question I have is. If I write a recipe that installs a RPM
package trough yum, then deploys config files in specific directories
and then restarts the enables and starts the service. Then have a
dependency on apache recipe and does and action [:restart] on httpd
service.

What does the chef recipe actualy do the second time chef runs? Does
it reinstalls the RPM and config files then restarts the httpd
service? Or does it do a diff to see if its the same package and skip
the installation and configfiles but restarts httpd?

Anyone who can enlighten me or point me to a RTFM page? =)

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT


#5

Can you perhaps explain a bit more about the notifies or/and send me
some info where to find it in the wiki if possible? =)
Just want the config files to deploy when I updates them and if thay
have been updated restart the service, else exit 0.
I know how to do it in bash, just not in ruby(chef) yet.

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT

2012/11/5 William Herry WilliamHerryChina@gmail.com:

it will not run again the second time chef runs, most of resources are and
every time chef client runs, it will chef the resource status, if it is not
we expected(like package is not been installed), it will take the action to
bring that part to the status we expected, if it is already in the status we
expected(like package already installed), it will do nothing

about config file and service, you may want to use notifies, which mainly
means when config file changes, send some single(like restart) to the
service resource

hope this help

On Mon, Nov 5, 2012 at 10:02 PM, Jens Skott jens.skott@schibsted.se wrote:

I have a question about RPM:s and config files with chef.
Im sorry if im writing a question I should find the answer to on the
site but have not found any information regarding it or I could just
have missed it.

The question I have is. If I write a recipe that installs a RPM
package trough yum, then deploys config files in specific directories
and then restarts the enables and starts the service. Then have a
dependency on apache recipe and does and action [:restart] on httpd
service.

What does the chef recipe actualy do the second time chef runs? Does
it reinstalls the RPM and config files then restarts the httpd
service? Or does it do a diff to see if its the same package and skip
the installation and configfiles but restarts httpd?

Anyone who can enlighten me or point me to a RTFM page? =)

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT


#6

On Monday, November 5, 2012 at 7:45 AM, Jens Skott wrote:

Can you perhaps explain a bit more about the notifies or/and send me
some info where to find it in the wiki if possible? =)
Just want the config files to deploy when I updates them and if thay
have been updated restart the service, else exit 0.
I know how to do it in bash, just not in ruby(chef) yet.

Here’s the section on this in the new docs:
http://docs.opscode.com/resource_common.html#notifications

And the previous set of docs on the wiki:

http://wiki.opscode.com/display/chef/Resources#Resources-Notifications

By the way, any feedback on the new docs would be really helpful.

Thanks and HTH,


Daniel DeLeo


#7

Aha.
No, it will only send the :restart action to the 'service[apache2]'
resource, if action needs to be taken to fix the config file.

-s

On Mon, Nov 5, 2012 at 10:30 AM, Jens Skott jens.skott@schibsted.se wrote:

But if i put a action [:restart] will it restart it every time the
client parses the recipe?
If so do I have to put it in a not_if thingy to make it not restart if
there are stuff present?

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT

2012/11/5 Sean OMeara someara@gmail.com:

TL;DR - Chef will probably do nothing on the second run.

Actual answer -

Chef will parse the recipe, compiling a “resource collection” that
looks something like:

[ ‘package[apache]’, ‘file[yourconfig]’, ‘service[apache]’ ]

Then, it will process the resources individually, in the order
generated by the recipe. Each resource will independently check to see
if it needs to take action to fix its subject through a provider,
potentially changing the system as it goes.

The package resource will consult the package manager to test if it
needs to install apache.
Think if [rpm -qa | grep apache] of if [dpkg -L | grep apache]
under the hood.

The file resource (and its cousins template, remote_file,
cookbook_file, etc) will take checksums in memory and against the file
on disk. If they differ, the one in memory wins and gets written,
leaving you a diff in your output. (logs, why-run, etc)

‘service[apache]’ will check to see if apache is running and fix it if
it isn’t, etc.

hope that helps

-s

On Mon, Nov 5, 2012 at 9:02 AM, Jens Skott jens.skott@schibsted.se wrote:

I have a question about RPM:s and config files with chef.
Im sorry if im writing a question I should find the answer to on the
site but have not found any information regarding it or I could just
have missed it.

The question I have is. If I write a recipe that installs a RPM
package trough yum, then deploys config files in specific directories
and then restarts the enables and starts the service. Then have a
dependency on apache recipe and does and action [:restart] on httpd
service.

What does the chef recipe actualy do the second time chef runs? Does
it reinstalls the RPM and config files then restarts the httpd
service? Or does it do a diff to see if its the same package and skip
the installation and configfiles but restarts httpd?

Anyone who can enlighten me or point me to a RTFM page? =)

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT


#8

you can use action :nothing in service resource

On Tue, Nov 6, 2012 at 12:02 AM, Sean OMeara someara@gmail.com wrote:

Aha.
No, it will only send the :restart action to the 'service[apache2]'
resource, if action needs to be taken to fix the config file.

-s

On Mon, Nov 5, 2012 at 10:30 AM, Jens Skott jens.skott@schibsted.se
wrote:

But if i put a action [:restart] will it restart it every time the
client parses the recipe?
If so do I have to put it in a not_if thingy to make it not restart if
there are stuff present?

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT

2012/11/5 Sean OMeara someara@gmail.com:

TL;DR - Chef will probably do nothing on the second run.

Actual answer -

Chef will parse the recipe, compiling a “resource collection” that
looks something like:

[ ‘package[apache]’, ‘file[yourconfig]’, ‘service[apache]’ ]

Then, it will process the resources individually, in the order
generated by the recipe. Each resource will independently check to see
if it needs to take action to fix its subject through a provider,
potentially changing the system as it goes.

The package resource will consult the package manager to test if it
needs to install apache.
Think if [rpm -qa | grep apache] of if [dpkg -L | grep apache]
under the hood.

The file resource (and its cousins template, remote_file,
cookbook_file, etc) will take checksums in memory and against the file
on disk. If they differ, the one in memory wins and gets written,
leaving you a diff in your output. (logs, why-run, etc)

‘service[apache]’ will check to see if apache is running and fix it if
it isn’t, etc.

hope that helps

-s

On Mon, Nov 5, 2012 at 9:02 AM, Jens Skott jens.skott@schibsted.se
wrote:

I have a question about RPM:s and config files with chef.
Im sorry if im writing a question I should find the answer to on the
site but have not found any information regarding it or I could just
have missed it.

The question I have is. If I write a recipe that installs a RPM
package trough yum, then deploys config files in specific directories
and then restarts the enables and starts the service. Then have a
dependency on apache recipe and does and action [:restart] on httpd
service.

What does the chef recipe actualy do the second time chef runs? Does
it reinstalls the RPM and config files then restarts the httpd
service? Or does it do a diff to see if its the same package and skip
the installation and configfiles but restarts httpd?

Anyone who can enlighten me or point me to a RTFM page? =)

Jens Skott
Tel: +46-8-5142 4396
Schibsted Centralen IT