Strange order execution of recipes, chef-solo


#1

Hello list,

So I have my own recipe, and it’s like an “aggregator” recipe, it’s the
only recipe in the run list for my node, and it in turn calls other recipes
in order to build the node and deploy a couple of apps.

My default.rb for this recipe looks like this:

include_recipe “build-essential”

include_recipe "user::data_bag"
include_recipe "sudo"
include_recipe "fullofcaffeine::setup_keys"
include_recipe “git::default” #sets up git
include_recipe “nginx::default” #installs nginx
include_recipe "runit"
include_recipe "unicorn"
include_recipe "ruby"
package "libpq-dev"
require_recipe "postgresql::client"
require_recipe "postgresql::server"
require_recipe “fullofcaffeine::deploy_rack_apps”

I’m cooking a new node now, and I just got the following error:

Error executing action create on resource

'file[/home/deploy/.ssh/id_deploy

This is caused by the “fullofcaffeine::setup_keys” recipe, which is pretty
simple, and looks like:

Handle ssh key for git private repo

secret =
Chef::EncryptedDataBagItem.load_secret(’/tmp/chef-solo/data_bag_key’)
secrets = Chef::EncryptedDataBagItem.load(“deploy_keys”,
“marcelo-laptop”,secret)
file “/home/deploy/.ssh/id_deploy” do
action :nothing
content secrets[“deploy_key”]
owner "deploy"
group "deploy"
mode '0600’
end.run_action(:create)

However, for some reason, the user::data_bag (
https://github.com/fnichol/chef-user) - the one that should have created
the deploy user before the setup of keys - did not run, and hence the
deploy key could not be written in the non-existent path for the deploy
user.

Any ideas why this happens? Any insights appreciated, I’m a bit lost here.

Thanks in advance,

  • Marcelo.

#2

You’re running that file resource :create action at compile time. Was that
your intention? Do you need this deploy key to be present at compile time?

I don’t believe the user::data_bag recipe does its work during compile
phase 0. Although, it could be modified to do so.

–AJ

On 27 November 2012 10:15, Marcelo de Moraes Serpa celoserpa@gmail.comwrote:

Hello list,

So I have my own recipe, and it’s like an “aggregator” recipe, it’s the
only recipe in the run list for my node, and it in turn calls other recipes
in order to build the node and deploy a couple of apps.

My default.rb for this recipe looks like this:

include_recipe “build-essential”

include_recipe "user::data_bag"
include_recipe "sudo"
include_recipe "fullofcaffeine::setup_keys"
include_recipe “git::default” #sets up git
include_recipe “nginx::default” #installs nginx
include_recipe "runit"
include_recipe "unicorn"
include_recipe "ruby"
package "libpq-dev"
require_recipe "postgresql::client"
require_recipe "postgresql::server"
require_recipe “fullofcaffeine::deploy_rack_apps”

I’m cooking a new node now, and I just got the following error:

Error executing action create on resource

'file[/home/deploy/.ssh/id_deploy

This is caused by the “fullofcaffeine::setup_keys” recipe, which is pretty
simple, and looks like:

Handle ssh key for git private repo

secret =
Chef::EncryptedDataBagItem.load_secret(’/tmp/chef-solo/data_bag_key’)
secrets = Chef::EncryptedDataBagItem.load(“deploy_keys”,
“marcelo-laptop”,secret)
file “/home/deploy/.ssh/id_deploy” do
action :nothing
content secrets[“deploy_key”]
owner "deploy"
group "deploy"
mode '0600’
end.run_action(:create)

However, for some reason, the user::data_bag (
https://github.com/fnichol/chef-user) - the one that should have created
the deploy user before the setup of keys - did not run, and hence the
deploy key could not be written in the non-existent path for the deploy
user.

Any ideas why this happens? Any insights appreciated, I’m a bit lost here.

Thanks in advance,

  • Marcelo.

#3

Hi AJ,

Thanks. The problem was that a File.read was trying to read the keyfile at
compile time it seems. I just added a File.exists?, as in:

application name do
path "/var/www/apps/#{name}"
owner deployment_user
group deployment_group
deploy_key File.read(app[‘deploy_key’]) if app[‘deploy_key’] &&
File.exists?(app[‘deploy_key’])

And it’s working fine now.

Cheers,

  • Marcelo.

On Mon, Nov 26, 2012 at 3:25 PM, AJ Christensen aj@junglist.gen.nz wrote:

You’re running that file resource :create action at compile time. Was that
your intention? Do you need this deploy key to be present at compile time?

I don’t believe the user::data_bag recipe does its work during compile
phase 0. Although, it could be modified to do so.

–AJ

On 27 November 2012 10:15, Marcelo de Moraes Serpa celoserpa@gmail.comwrote:

Hello list,

So I have my own recipe, and it’s like an “aggregator” recipe, it’s the
only recipe in the run list for my node, and it in turn calls other recipes
in order to build the node and deploy a couple of apps.

My default.rb for this recipe looks like this:

include_recipe “build-essential”

include_recipe "user::data_bag"
include_recipe "sudo"
include_recipe "fullofcaffeine::setup_keys"
include_recipe “git::default” #sets up git
include_recipe “nginx::default” #installs nginx
include_recipe "runit"
include_recipe "unicorn"
include_recipe "ruby"
package "libpq-dev"
require_recipe "postgresql::client"
require_recipe "postgresql::server"
require_recipe “fullofcaffeine::deploy_rack_apps”

I’m cooking a new node now, and I just got the following error:

Error executing action create on resource

'file[/home/deploy/.ssh/id_deploy

This is caused by the “fullofcaffeine::setup_keys” recipe, which is
pretty simple, and looks like:

Handle ssh key for git private repo

secret =
Chef::EncryptedDataBagItem.load_secret(’/tmp/chef-solo/data_bag_key’)
secrets = Chef::EncryptedDataBagItem.load(“deploy_keys”,
“marcelo-laptop”,secret)
file “/home/deploy/.ssh/id_deploy” do
action :nothing
content secrets[“deploy_key”]
owner "deploy"
group "deploy"
mode '0600’
end.run_action(:create)

However, for some reason, the user::data_bag (
https://github.com/fnichol/chef-user) - the one that should have created
the deploy user before the setup of keys - did not run, and hence the
deploy key could not be written in the non-existent path for the deploy
user.

Any ideas why this happens? Any insights appreciated, I’m a bit lost here.

Thanks in advance,

  • Marcelo.