Month: May 2018

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.

 

Prevent Mac hidden files being written to a shared storage

MacOS tends to trash mounted disks with number of useless hidden files (e.g. ._* or .DS_Store ). There were number of recipes in the Internet, some of them were working at some of time but are not anymore.

Below notes from my fights (at a moment of writing, on MacOS High Sierra 10.13.4 (17E199).

Removing the files when they are created

I used to apply a find . -name … -print0 | xargs rm -0  combo but found that there is an built-in command to deal with these files:

$ dot_clean .

From the man:

NAME
dot_clean -- Merge ._* files with corresponding native files.

SYNOPSIS
dot_clean [-fmnsv] [--keep=[mostrecent|dotbar|native]] [dir ...]

DESCRIPTION
For each dir, dot_clean recursively merges all ._* files with their corresponding native files according to the rules specified with the given arguments. By default, if there is an attribute on the native file that is also present in the ._ file, the most recent attribute will be used.

Preventing creating the files

On the MacOS side

NOTE: None of these solutions worked for me!

$ defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
$ killall Finder

As I wrote, this didn’t work at all to me.

On the SMB server side

It actually turned the only working solution for me. Just add to the share configuration section a veto file parameter, e.g.:

$ sudo vi /etc/samba/smb.conf
[jhartman]
 path = /home/jhartman
.....
 veto files = /._*/.DS_Store/

And restart:

$ sudo service smbd restart

Note, after applying this change you will not be able anymore to use dot_clean  command from your Mac as any requests towards these files (including deletion) will be silently ignored by your SMB server hence files will remain untouched!