[chef] Re: Chef::Exceptions::FileTypeMismatch


Chronological Thread 
  • From: "steve ." < >
  • To: " " < >
  • Subject: [chef] Re: Chef::Exceptions::FileTypeMismatch
  • Date: Sun, 28 Jul 2013 00:25:50 -0700

Hi David,

The reason you're seeing that "File Type Mismatch" exception is that your override isn't working, causing your cookbook_file resource and your directory resource to clash.  (Sorry.  You probably knew that.)

I think you have some malformed JSON.  Run it through an online validator to be sure.  (I went in circles for days with RunDeck ACLs and the culprit turned out to be malformed YAML.  Live and learn!)

Change:
"override_attributes": {
                             "environment":{"chef":{"validation_key":"t1"}},
                             "environment":{"chef":{"client_key":"t2"}}       # <--- here you clobber [:environment][:chef] so that it no longer has [:validation_key] in it!
}

To:

  "override_attributes": {
    "environment": {
      "chef": {
        "validation_key": "t1",
        "client_key": "t2"
      }
    }
  }


OK, now that your recipe will hopefully work the way you want it, I'd like you to think about something: You're relying on the consumer of this cookbook ("Future You," "The Rest of Your Team," "The Internet," whoever) to override node attributes, or the recipe won't work.

I suggest modifying your recipe to provide a sane default behavior for those node attributes and to have it check to see if the local variables are assigned nil values ... and either fix it so that things work or tell the user they're going to have a bad time _and why_.  Otherwise, someone might tear their hair out over this some day...



On Sat, Jul 27, 2013 at 11:54 PM, David Montgomery < " target="_blank"> > wrote:
Why will this not work?  I am trying to use a override for a cookbook file.  Yet I get the below error

In Attributes:

default['environment']['chef']['validation_key'] = nil
default['environment']['chef']['client_key'] = nil


In recipe:


directory "/home/ubuntu/.chef" do
  owner "ubuntu"
  group "ubuntu"
  mode "0755"
  recursive true
  action :create
end

validation_key = node['environment']['chef']['validation_key']
client_key = node['environment']['chef']['client_key']

cookbook_file "/home/ubuntu/.chef/#{validation_key}" do
  source "#{validation_key}"
  mode 00644
end
cookbook_file "/home/ubuntu/.chef/#{client_key}" do
  source "#{client_key}"
  mode 00644
end



In role with override attribute

"override_attributes": {
                             "environment":{"chef":{"validation_key":"t1"}},
                             "environment":{"chef":{"client_key":"t2"}}   
}






================================================================================
Error executing action `create` on resource 'cookbook_file[/home/ubuntu/.chef/]'
================================================================================


Chef::Exceptions::FileTypeMismatch
----------------------------------
File /home/ubuntu/.chef/ exists, but is a directory, set force_unlink to true to remove


Resource Declaration:
---------------------
# In /home/ubuntu/workspace/chef-repo/cookbooks/environment/recipes/local_chef.rb

 20: cookbook_file "/home/ubuntu/.chef/#{validation_key}" do
 21:   source "#{validation_key}"
 22:   mode 00644
 23: end
 24: cookbook_file "/home/ubuntu/.chef/#{client_key}" do



Compiled Resource:
------------------
# Declared in /home/ubuntu/workspace/chef-repo/cookbooks/environment/recipes/local_chef.rb:20:in `from_file'

cookbook_file("/home/ubuntu/.chef/") do
  provider Chef::Provider::CookbookFile
  action "create"
  retries 0
  retry_delay 2
  path "/home/ubuntu/.chef/"
  backup 5
  atomic_update true
  cookbook_name :environment
  recipe_name "local_chef"
  mode 420
end






Archive powered by MHonArc 2.6.16.

§