Chef resources failing with wrong constant name

When trying to add a custom resource, no matter what, I always got a wrong constant name  error, for example:

resolving cookbooks for run list: ["01_test-cookbook"]
Synchronizing Cookbooks:
  - test-cookbook (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...

================================================================================
Recipe Compile Error in /home/jhartman/.chef/local-mode-cache/cache/cookbooks/test-cookbook/resources/append_line.rb
================================================================================

NameError
---------
wrong constant name 01TestCookbookAppendLine

Platform:
---------
x86_64-linux-gnu

It turned out to be an issue with my cookbook name: it’s not allowed to have a cookbook name starting with a number (as later, it’s converted into a class name).

So my cookbooks as below are causing the problems:

drwxrwxr-x 8 jhartman jhartman 15 Apr 22 21:45 1_PreRequisites
drwxrwxr-x 7 jhartman jhartman 14 Apr 22 23:38 2_OracleDB
drwxrwxr-x 9 jhartman jhartman 16 May  3 18:12 3_NCC
drwxrwxr-x 6 jhartman jhartman 13 Apr 22 22:22 4_PostInstallation

They should be renamed into something else, for example:

drwxrwxr-x 8 jhartman jhartman 15 Apr 22 21:45 A_PreRequisites
drwxrwxr-x 7 jhartman jhartman 14 Apr 22 23:38 B_OracleDB
drwxrwxr-x 9 jhartman jhartman 16 May  3 18:12 C_NCC
drwxrwxr-x 6 jhartman jhartman 13 Apr 22 22:22 D_PostInstallation

Note, inside the files, there are references to the names, so you may need to update them accordingly, for example using:

$ find . -type f -print0 | xargs -0 sed -i 's/2_OracleDB/B_OracleDB/g'

After this, no more strange errors after adding resources.

PS: When you work on MacOS, you may face another problem with your resources: MacOS trash files (._* or .DS_Store) are causing another (similarly looking) error. Take a look at this web page.

 

Chef resources failing with wrong constant name
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *