[chef] recipes run order versus resource usage/cloning


Chronological Thread 
  • From: johnnym < >
  • To:
  • Subject: [chef] recipes run order versus resource usage/cloning
  • Date: Tue, 01 Apr 2014 17:06:53 +0200

Hi All,

I am new to chef so sorry if I misuse some words but I have a question. As I tested it if a node has 2 recipes and these recipes work on the same resource (a file or a package...or user) how can I prevent the node from rebuilding and restarting services all the time.

In this case I make a base system with the minimal packages services and users, but with a specific base config file. On this base system I want to create a backend so I apply B::backend but this recipe installs packages, adds users and modifies a config file.

If I run chef-client (below) I can see that the users, packages and files are removing and reinstalling all the time and the services are restarting during every chef-client run.

Can I compile the recipes into one recipe in order to allow them to overwrite the same resource in the order of the run_list?

{
  "name": "javatest03xd.origo.t-online.private",
  "chef_environment": "test",
...
  "run_list": [
    "recipe[A::base]",
    "recipe[B::backend]"
  ]
}

A/base.rb
package "nfs-common" do
  action :remove
end

service 'ntp' do
  action [:enable, :start]
end

file "/tmp/very_important_service.conf" do
    content "BASE data"
    notifies  :restart, 'service[ntp]'
end

user 'extra' do
    action [:remove ]
end


B/backend.rb
package "nfs-common" do
  action :remove
end
service 'ntp' do
  action [:enable, :start]
end

file "/tmp/very_important_service.conf" do
    content "BACKEND data"
    notifies  :restart, 'service[ntp]'
end

user 'extra' do
    action [:create, :lock]
end

[2014-04-01T16:59:55+02:00] INFO: Forking chef instance to converge...
[2014-04-01T16:59:55+02:00] INFO: *** Chef 11.10.4 ***
[2014-04-01T16:59:55+02:00] INFO: Chef-client pid: 7730
[2014-04-01T16:59:56+02:00] INFO: Run List is [recipe[A::base], recipe[B::backend]]
[2014-04-01T16:59:56+02:00] INFO: Run List expands to [A::base, B::backend]
[2014-04-01T16:59:56+02:00] INFO: Starting Chef Run for javatest03xd.origo.t-online.private
[2014-04-01T16:59:56+02:00] INFO: Running start handlers
[2014-04-01T16:59:56+02:00] INFO: Start handlers complete.
[2014-04-01T16:59:56+02:00] INFO: HTTP Request Returned 404 Object Not Found: 
[2014-04-01T16:59:56+02:00] INFO: Loading cookbooks [A, B]
[2014-04-01T16:59:56+02:00] WARN: Cloning resource attributes for package[nfs-common] from prior resource (CHEF-3694)
[2014-04-01T16:59:56+02:00] WARN: Previous package[nfs-common]: /var/chef/cache/cookbooks/A/recipes/base.rb:1:in `from_file'
[2014-04-01T16:59:56+02:00] WARN: Current  package[nfs-common]: /var/chef/cache/cookbooks/B/recipes/backend.rb:1:in `from_file'
[2014-04-01T16:59:56+02:00] WARN: Cloning resource attributes for service[ntp] from prior resource (CHEF-3694)
[2014-04-01T16:59:56+02:00] WARN: Previous service[ntp]: /var/chef/cache/cookbooks/A/recipes/base.rb:5:in `from_file'
[2014-04-01T16:59:56+02:00] WARN: Current  service[ntp]: /var/chef/cache/cookbooks/B/recipes/backend.rb:5:in `from_file'
[2014-04-01T16:59:56+02:00] WARN: Cloning resource attributes for file[/tmp/very_important_service.conf] from prior resource (CHEF-3694)
[2014-04-01T16:59:56+02:00] WARN: Previous file[/tmp/very_important_service.conf]: /var/chef/cache/cookbooks/A/recipes/base.rb:9:in `from_file'
[2014-04-01T16:59:56+02:00] WARN: Current  file[/tmp/very_important_service.conf]: /var/chef/cache/cookbooks/B/recipes/backend.rb:9:in `from_file'
[2014-04-01T16:59:56+02:00] WARN: Cloning resource attributes for user[extra] from prior resource (CHEF-3694)
[2014-04-01T16:59:56+02:00] WARN: Previous user[extra]: /var/chef/cache/cookbooks/A/recipes/base.rb:14:in `from_file'
[2014-04-01T16:59:56+02:00] WARN: Current  user[extra]: /var/chef/cache/cookbooks/B/recipes/backend.rb:14:in `from_file'
[2014-04-01T16:59:56+02:00] INFO: Processing package[nfs-common] action remove (A::base line 1)
[2014-04-01T16:59:57+02:00] INFO: package[nfs-common] removed
[2014-04-01T16:59:57+02:00] INFO: Processing service[ntp] action enable (A::base line 5)
[2014-04-01T16:59:57+02:00] INFO: Processing service[ntp] action start (A::base line 5)
[2014-04-01T16:59:57+02:00] INFO: Processing file[/tmp/very_important_service.conf] action create (A::base line 9)
[2014-04-01T16:59:57+02:00] INFO: file[/tmp/very_important_service.conf] backed up to /var/chef/backup/tmp/very_important_service.conf.chef-20140401165957.690683
[2014-04-01T16:59:57+02:00] INFO: file[/tmp/very_important_service.conf] updated file contents /tmp/very_important_service.conf
[2014-04-01T16:59:57+02:00] INFO: file[/tmp/very_important_service.conf] not queuing delayed action restart on service[ntp] (delayed), as it's already been queued
[2014-04-01T16:59:57+02:00] INFO: Processing user[extra] action remove (A::base line 14)
[2014-04-01T16:59:57+02:00] INFO: user[extra] removed
[2014-04-01T16:59:57+02:00] INFO: Processing package[nfs-common] action install (B::backend line 1)
[2014-04-01T17:00:00+02:00] INFO: Processing service[ntp] action enable (B::backend line 5)
[2014-04-01T17:00:00+02:00] INFO: Processing service[ntp] action start (B::backend line 5)
[2014-04-01T17:00:00+02:00] INFO: Processing file[/tmp/very_important_service.conf] action create (B::backend line 9)
[2014-04-01T17:00:00+02:00] INFO: file[/tmp/very_important_service.conf] backed up to /var/chef/backup/tmp/very_important_service.conf.chef-20140401170000.881799
[2014-04-01T17:00:00+02:00] INFO: file[/tmp/very_important_service.conf] updated file contents /tmp/very_important_service.conf
[2014-04-01T17:00:00+02:00] INFO: file[/tmp/very_important_service.conf] not queuing delayed action restart on service[ntp] (delayed), as it's already been queued
[2014-04-01T17:00:00+02:00] INFO: file[/tmp/very_important_service.conf] not queuing delayed action restart on service[ntp] (delayed), as it's already been queued
[2014-04-01T17:00:00+02:00] INFO: Processing user[extra] action create (B::backend line 14)
[2014-04-01T17:00:00+02:00] INFO: user[extra] created
[2014-04-01T17:00:00+02:00] INFO: Processing user[extra] action lock (B::backend line 14)
[2014-04-01T17:00:01+02:00] INFO: file[/tmp/very_important_service.conf] sending restart action to service[ntp] (delayed)
[2014-04-01T17:00:01+02:00] INFO: Processing service[ntp] action restart (B::backend line 5)
[2014-04-01T17:00:02+02:00] INFO: service[ntp] restarted
[2014-04-01T17:00:02+02:00] INFO: Chef Run complete in 6.074158866 seconds
[2014-04-01T17:00:02+02:00] INFO: Running report handlers
[2014-04-01T17:00:02+02:00] INFO: Report handlers complete


I hope I could explain my question clearly.

Best, Balint!



Archive powered by MHonArc 2.6.16.

§