[chef] Re: Re: Re: Re: Malformed array causing Chef to error out


Chronological Thread 
  • From: Fabien Delpierre < >
  • To: chef < >
  • Subject: [chef] Re: Re: Re: Re: Malformed array causing Chef to error out
  • Date: Thu, 26 Feb 2015 14:30:23 -0500

Ranjib,
Perhaps I'm looking at the permissions thing the wrong way, but here's how I understand it: I want the files and directories I'm creating to be owned by the vagrant user and the root group.
/tmp/vagrant-chef is owned by vagrant:root, however the directory underneath that, /tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb is owned by root:root. This is a folder provisioned automatically by Vagrant/Berkshelf, not by Chef, and I don't know if I can customize the ownership, or how I would do that, nor am I really concerned with that so long as it doesn't cause me any trouble :)

And to your question about why I'm creating data bag paths, well, again, perhaps I'm doing it wrong, but they currently don't exist, and I want them to exist. I'm using Chef-Solo, not Chef-Client. I'm not new to Chef-Client, but I've never used Chef-Solo so I'm still learning the differences.

We saw earlier that Chef::Config[:data_bag_path].first = /tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags but before I run this code to create the directories and files I need, there is no data_bags directory under /tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb, so I need to create it and place a data bag item in it. The reason why I need a data bag at all is because I'm trying to store credentials for AWS S3 so I can then use the aws_s3_file resource from the aws cookbook. I've never had to use that cookbook but it says I should use a data bag to store the AWS credentials. I probably don't have to, but I'm going to need to use data bags to store some secrets for something else later. Or maybe I don't actually have to use data bags for this next thing I'm thinking, but I'll need to figure out where to put all the secrets I need to pass to the app for it to work.

On Thu, Feb 26, 2015 at 1:48 PM, Ranjib Dey < " target="_blank"> > wrote:
Why is Chef::Config[:data_bag_path] an array?
- because you can have multiple folder containing the data bags. this is similar to cookbook_path. In your case you can just use .first.
Recursive directory and permission:
- If any of the parent directory exist should Chef change its permission? Is that intended? If chef creates one of the parent directory the dafault permissions will  govern by umask etc.. should chef change that? Current behavior is to leave them as it is (or let umask govern them). I find it safer

just curious why you are trying to create data bag paths?


On Thu, Feb 26, 2015 at 10:19 AM, Fabien Delpierre < " target="_blank"> > wrote:
Thanks.
Why is Chef::Config[:data_bag_path] an array, though?
Also, you may have noticed I already have the recursive attribute set to true, but per the docs, it doesn't apply recursive permissions, and I want to set the right permissions on both folders.

Anyway, I commented out the code I posted earlier and used this instead:

directory "#{Chef::Config[:data_bag_path]}/#{node['nap']['data_bag']}" do
  owner node['nap']['provisioning_owner']
  group node['nap']['provisioning_group']
  mode 00440
  recursive true
  action :create
end

The Chef run ran successfully. The run output says:
==> default: [2015-02-26T13:12:59-05:00] INFO: directory[["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]/nap-vagrant] created directory ["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]/nap-vagrant
==> default: [2015-02-26T13:12:59-05:00] INFO: directory[["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]/nap-vagrant] owner changed to 500
==> default: [2015-02-26T13:12:59-05:00] INFO: directory[["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]/nap-vagrant] group changed to 0
==> default: [2015-02-26T13:12:59-05:00] INFO: directory[["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]/nap-vagrant] mode changed to 440

You can see the brackets are still there and it looks fishy. Sure enough, /tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags does not exist. However I now have a folder directly under / called '["' with the above directory structure underneath it, i.e. /["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]

So I'm still in trouble :)

On Thu, Feb 26, 2015 at 1:03 PM, Brandon Raabe < " target="_blank"> > wrote:
It looks like your first entry is an array.

dirs = [ Chef::Config[:data_bag_path], "#{Chef::Config[:data_bag_path]}/#{node['data_bag']}" ]

directory("["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]") do

You can force it to create the entire path by adding the recursive attribute to you directory resource.


On Thu, Feb 26, 2015 at 10:40 AM, Fabien Delpierre < " target="_blank"> > wrote:
Hi there,
I can't figure out what I'm doing wrong with this. It seems trivial enough but I'm not a software developer and this is puzzling me right now. I think my issue has more to do with pure Ruby than Chef but either way, I can't figure it out.
If it matters, I'm working with chef-solo 12.0.3 and provisioning things via Vagrant 1.7.2.

I'm doing something that should be pretty straightforward: creating a number of directories declared in an array:

dirs = [ Chef::Config[:data_bag_path], "#{Chef::Config[:data_bag_path]}/#{node['data_bag']}" ]

dirs.each do |dir|
  directory dir do
    owner "foo"
    group "foo"
    mode 00440
    recursive true
    action :create
  end
end


This results in the following error during provisioning
==> default: Compiled Resource:
==> default: ------------------
==> default: # Declared in /tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/cookbooks/nap/recipes/default.rb:90:in `block in from_file'
==> default:
==> default: directory("["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]") do
==> default:   action [:create]
==> default:   retries 0
==> default:   retry_delay 2
==> default:   default_guard_interpreter :default
==> default:   path ["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]
==> default:   recursive true
==> default:   declared_type :directory
==> default:   cookbook_name :nap
==> default:   recipe_name "default"
==> default:   owner "foo"
==> default:   group "foo"
==> default:   mode 288
==> default: end
==> default:
==> default: [2015-02-26T12:09:20-05:00] INFO: Running queued delayed notifications before re-raising exception
==> default: [2015-02-26T12:09:20-05:00] ERROR: Running exception handlers
==> default: [2015-02-26T12:09:20-05:00] ERROR: Exception handlers complete
==> default: [2015-02-26T12:09:20-05:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2015-02-26T12:09:20-05:00] ERROR: directory[["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]] (nap::default line 90) had an error: Chef::Exceptions::ValidationFailed: Option path must be a kind of String!  You passed ["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"].
==> default: [2015-02-26T12:09:21-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)


I ran this through chef-shell as well:
$ chef-shell -s -c solo.rb
loading configuration: solo.rb
Session type: solo
Loading.............done.
Ohai2u
chef > puts Chef::Config[:data_bag_path]
/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags
 => nil
chef > dirs = [ Chef::Config[:data_bag_path], "#{Chef::Config[:data_bag_path]}/#{node['foo']['bar']}" ]
NoMethodError: undefined method `[]' for nil:NilClass
    from (irb):3
    from /opt/chef/embedded/apps/chef/lib/chef/shell.rb:75:in `block in start'
    from /opt/chef/embedded/apps/chef/lib/chef/shell.rb:74:in `catch'
    from /opt/chef/embedded/apps/chef/lib/chef/shell.rb:74:in `start'
    from /opt/chef/embedded/apps/chef/bin/chef-shell:37:in `<top (required)>'
    from /usr/bin/chef-shell:40:in `load'
    from /usr/bin/chef-shell:40:in `<main>'
chef > dirs = []
 => []
chef > dirs = [ Chef::Config[:data_bag_path] ]
 => [["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]]
chef > puts dirs
/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags
 => nil
chef > dirs = [ Chef::Config[:data_bag_path], "#{Chef::Config[:data_bag_path]}/test" ]
 => [["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"], "[\"/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags\"]/test"]
chef > puts dirs
/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags
["/tmp/vagrant-chef/c0f72feb81f20d85ca657a73371fcecb/data_bags"]/test
 => nil
chef >


So as you can see in the above output, it's adding brackets around some of the things stored in the array and that seems to be why the Chef run is failing, but I don't understand why adding the brackets to begin with.

I also have no idea why this line produces an error:
chef > dirs = [ Chef::Config[:data_bag_path], "#{Chef::Config[:data_bag_path]}/#{node['foo']['bar']}" ]

Would somebody please mind explaining what I'm doing wrong? Thank you!







Archive powered by MHonArc 2.6.16.

§