Chef: ¿Por qué se omiten los recursos en un paso de "incluir receta"?


Chef parece estar procesando recursos en un orden extraño, causando que mi compilación falle. Mi receta principal (mytardis-chef/site-cookbooks/recipes/default.rb) comienza así:

include_recipe "build-essential"
include_recipe "mytardis::deps"
include_recipe "mytardis::nginx"
include_recipe "mytardis::postgresql"

mytardis-chef/cookbooks/build-essential/recipes/default.rb se ve así:

case node['platform']
when "ubuntu","debian"
  %w{build-essential binutils-doc}.each do |pkg|
    package pkg do
      action :install
    end
  end
when "centos","redhat","fedora","scientific"
  %w{gcc gcc-c++ kernel-devel make}.each do |pkg|
    package pkg do
      action :install
    end
  end
end

... (es una versión anterior de https://github.com/opscode-cookbooks/build-essential/blob/master/recipes/default.rb)

En tiempo de ejecución, por razones que no entiendo, esta receta esencial de compilación se carga pero no se ejecuta:

[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant
[default] -- v-csr-3: /tmp/vagrant-chef-1/chef-solo-3/roles
[default] -- v-csc-2: /tmp/vagrant-chef-1/chef-solo-2/cookbooks
[default] -- v-csc-1: /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[default] -- v-csdb-4: /tmp/vagrant-chef-1/chef-solo-4/data_bags
[default] Running provisioner: Vagrant::Provisioners::ChefSolo...
[default] Generating chef JSON and uploading...
[default] Running chef-solo...
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: *** Chef 10.12.0 ***
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Building node object for lucid32
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Extracting run list from JSON attributes provided on command line
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Setting the run_list to ["recipe[mytardis]"] from JSON
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Applying attributes from json file
[Sun, 08 Jul 2012 05:14:32 +0200] DEBUG: Platform is ubuntu version 10.04
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Run List is [recipe[mytardis]]
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Run List expands to [mytardis]
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Starting Chef Run for lucid32
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Running start handlers
[Sun, 08 Jul 2012 05:14:32 +0200] INFO: Start handlers complete.
...
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe default in cookbook mytardis
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe build-essential via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe default in cookbook build-essential
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis::deps via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe deps in cookbook mytardis
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis::nginx via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe nginx in cookbook mytardis
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe iptables via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe default in cookbook iptables
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe mytardis::postgresql via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe postgresql in cookbook mytardis
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe postgresql::server via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe server in cookbook postgresql
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Loading Recipe postgresql::client via include_recipe
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: Found recipe client in cookbook postgresql
[Sun, 08 Jul 2012 05:14:33 +0200] INFO: Processing package[postgresql-client] action install (postgresql::client line 37)
[Sun, 08 Jul 2012 05:14:33 +0200] DEBUG: package[postgresql-client] checking package status for postgresql-client
....
[Sun, 08 Jul 2012 05:14:45 +0200] ERROR: gem_package[pg] (postgresql::client line 42) has had an error
.
make
sh: make: not found

Es decir, la receta esencial de construcción es "encontrada" y "cargada", pero es la receta postgres la que se "procesa" primero. Y desde build-essential (que instala el compilador de C) no se ejecutó, este último falla.

La parte relevante de mi Vagrantfile se ve así:

  config.vm.provision :chef_solo do |chef|
     chef.log_level = :debug
     chef.cookbooks_path = ["mytardis-chef/site-cookbooks", "mytardis-chef/cookbooks"]
     chef.roles_path = "mytardis-chef/roles"
     chef.data_bags_path = "mytardis-chef/data_bags"
     chef.add_recipe "mytardis"    
  end

Anteriormente estaba usando una versión ligeramente anterior de Chef (quizás 10.10.0?) En esa versión, build-essential tampoco se estaba ejecutando, pero mytardis:: deps sí. Ahora usando Chef 10.12.0. La máquina física es OSX, VM es Ubuntu Lucid.

Entonces, algunas preguntas:

  1. ¿Por qué no es esencial construir "procesado"?
  2. ¿Cuál es la manera correcta de hacer esto? (Yo no escribí estas recetas, y entiendo que lo hacen o han trabajado para su autor.)
  3. ¿Debería seguir funcionando la función site-cookbooks y cookbooks 'shadowing'? Se supone que está en desuso: http://tickets.opscode.com/browse/CHEF-2308 (Traté de hacer un enlace simbólico bajo from site-cookbooks/mytardis/recipes/build-essential but no joy).
Author: Steve Bennett, 2012-07-08

2 answers

Resulta que esta es una parte bastante normal (pero poco documentada) de cómo funciona Chef: compila todo, y luego comienza a ejecutarse. Excepto que algunas recetas (como Postgres) saltan la cola para instalar realmente en tiempo de compilación, usando código como este:

  action :nothing
end.run_action(:run)

La solución es que cualquier cosa que necesite ejecutarse antes de Postgres también necesita hacerlo. Afortunadamente, las versiones más recientes de Build-essentials permiten esto. Se establecen atributos en un rol de la siguiente manera:

name "myapp"
run_list(
  "recipe[build-essential]",
  "recipe[myapp]"
)
default_attributes(
  "build_essential" => {
    "compiletime" => true
  }
)
 40
Author: Steve Bennett,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-18 02:11:59

Si escribe un libro de cocina, agregue el atributo a su archivo de atributos:

node.default['build_essential']['compiletime'] = true

Gracias a Colin arriba.

 6
Author: toobulkeh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-03 20:44:22