Invalid argument for Chef Directory Resource? Any Ideas why - ruby

So, I have the following code which is a ruby block that opens a file on disk and reads each line. Each line is a string that is a dataversion (example: "2020_Q1_NA")
I am reading the file which has a UTF16 BOM encoding, so I open the file with that in mind, and convert each line to UTF-8. Then in the next step, I am creating a directory on D drive for each of the data versions. I am using a Dynamically Created Resource here, because the file I open is actually modified by a powershell_script resource right before the ruby_block resource.
I also tried a non dynamically created directory resource, and that also had the same error, so that isn't the problem
Anyways, I am getting the following error
Errno::EINVAL: directory[d:/Program Files/ALK/data/PCM/2020_Q1_NA
] (dynamically defined) had an error: Errno::EINVAL: Invalid argument - d:/Program Files/ALK/data/PCM/2020_Q1_NA
ruby_block 'get the dataversions and the paths' do
block do
File.open('C:\\deploy\\chefpackages\\alk_pcmworker\\cookbooks\\alk_pcmworker\\dataversions.json', 'rb:BOM|UTF-16LE') do |f|
f.each_line do |line|
dataversion = line.encode("UTF-8", "UTF-16LE")
puts dataversion.encoding # UTF-8
dataversionPath = File.join(node['alk']['dataversions']['datafilesroot'], dataversion)
resource = Chef::Resource::Directory.new(dataversionPath, run_context)
resource.rights(:full_control, 'Administrators', applies_to_children: true)
resource.rights(:read_execute, 'IIS_IUSRS', applies_to_children: true)
resource.recursive(true)
resource.run_action(:create)
end
end
end
action :run
end
I believe it is the dataversion variable that I encoded to UTF-8 that is causing the problem since if I statically set the variable to "2020_Q1_NA", the directory resource will get created, but the encoding is causing some problem, in my findings.
Is there something I am missing and how do I get past this problem. I added the stack trace for the chef recipe as well?
STACKTRACE
Generated at 2021-01-13 09:12:37 -0500
Errno::EINVAL: ruby_block[get the dataversions and the paths] (alk_pcmworker::data_instancestore line 32) had an error: Errno::EINVAL: directory[d:/Program Files/ALK/data/PCM/2020_Q1_NA
] (dynamically defined) had an error: Errno::EINVAL: Invalid argument - d:/Program Files/ALK/data/PCM/2020_Q1_NA
C:/opscode/chef/embedded/lib/ruby/2.0.0/fileutils.rb:245:in `mkdir'
C:/opscode/chef/embedded/lib/ruby/2.0.0/fileutils.rb:245:in `fu_mkdir'
C:/opscode/chef/embedded/lib/ruby/2.0.0/fileutils.rb:219:in `block (2 levels) in mkdir_p'
C:/opscode/chef/embedded/lib/ruby/2.0.0/fileutils.rb:217:in `reverse_each'
C:/opscode/chef/embedded/lib/ruby/2.0.0/fileutils.rb:217:in `block in mkdir_p'
C:/opscode/chef/embedded/lib/ruby/2.0.0/fileutils.rb:203:in `each'
C:/opscode/chef/embedded/lib/ruby/2.0.0/fileutils.rb:203:in `mkdir_p'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider/directory.rb:118:in `block in action_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/mixin/why_run.rb:52:in `call'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/mixin/why_run.rb:52:in `add_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider.rb:175:in `converge_by'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider/directory.rb:116:in `action_create'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider.rb:144:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource.rb:596:in `run_action'
C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/alk_pcmworker/recipes/data_instancestore.rb:49:in `block (4 levels) in from_file'
C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/alk_pcmworker/recipes/data_instancestore.rb:37:in `each_line'
C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/alk_pcmworker/recipes/data_instancestore.rb:37:in `block (3 levels) in from_file'
C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/alk_pcmworker/recipes/data_instancestore.rb:36:in `open'
C:/Users/Administrator/.chef/local-mode-cache/cache/cookbooks/alk_pcmworker/recipes/data_instancestore.rb:36:in `block (2 levels) in from_file'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider/ruby_block.rb:35:in `call'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider/ruby_block.rb:35:in `block in action_run'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/mixin/why_run.rb:52:in `call'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/mixin/why_run.rb:52:in `add_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider.rb:175:in `converge_by'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider/ruby_block.rb:34:in `action_run'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/provider.rb:144:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource.rb:596:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/runner.rb:74:in `run_action'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/runner.rb:106:in `block (2 levels) in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/runner.rb:106:in `each'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/runner.rb:106:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource_collection/resource_list.rb:83:in `block in execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/resource_collection/resource_list.rb:81:in `execute_each_resource'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/runner.rb:105:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/client.rb:658:in `block in converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/client.rb:653:in `catch'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/client.rb:653:in `converge'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/client.rb:692:in `converge_and_save'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/client.rb:271:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application.rb:243:in `run_with_graceful_exit_option'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application.rb:220:in `block in run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/local_mode.rb:44:in `with_server_connectivity'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application.rb:203:in `run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application/client.rb:413:in `block in interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application/client.rb:403:in `loop'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application/client.rb:403:in `interval_run_chef_client'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application/client.rb:393:in `run_application'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/lib/chef/application.rb:58:in `run'
C:/opscode/chef/embedded/lib/ruby/gems/2.0.0/gems/chef-12.6.0-universal-mingw32/bin/chef-client:26:in `<top (required)>'
C:/opscode/chef/bin/chef-client:64:in `load'
C:/opscode/chef/bin/chef-client:64:in `<main>'

Right now, I just solved this problem, by just doing the following. After the conversion, I did a inspect on the string and it had special characters, so I just removed them. This isn't the best way probably, but it solved the problem. The issue was special characters that were still there even though the string said it was UTF-8. The directory resource did create the custom folders now!!
dataversion = line.encode("UTF-8", "UTF-16LE")
dataversion = dataversion.inspect
# deleting leftover special characters
dataversion.delete! '"\\\r\\\n'

Related

initialize : malformed version number string data (ArgumentError)

I added a new folder ./data inside boxes\ubuntu-xenial64\ and edited the Vagrantfile by uncommenting this line:
config.vm.synced_folder "./data", "/vagrant_data"
Getting error as below:
PS C:\Users\sridh\.vagrant.d\boxes\ubuntu-VAGRANTSLASH-xenial64> vagrant up
C:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/2.3.0/rubygems/version.rb:207:in `initialize': Malformed version number string data (ArgumentError)
from C:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/2.3.0/rubygems/version.rb:199:in `new'
from C:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/2.3.0/rubygems/version.rb:199:in `new'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/box_collection.rb:289:in `block (2 levels) in find'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/box_collection.rb:285:in `map'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/box_collection.rb:285:in `block in find'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/box_collection.rb:448:in `block in with_collection_lock'
from C:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/box_collection.rb:447:in `with_collection_lock'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/box_collection.rb:271:in `find'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/vagrantfile.rb:167:in `block in machine_config'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/vagrantfile.rb:200:in `machine_config'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/vagrantfile.rb:45:in `machine'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/environment.rb:733:in `machine'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/plugin/v2/command.rb:177:in `block in with_target_vms'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/plugin/v2/command.rb:201:in `block in with_target_vms'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/plugin/v2/command.rb:183:in `each'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/plugin/v2/command.rb:183:in `with_target_vms'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/plugins/commands/up/command.rb:87:in `execute'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/cli.rb:42:in `execute'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/lib/vagrant/environment.rb:308:in `cli'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.8/bin/vagrant:138:in `<main>'

Homestead vagrant up error

/Users/shaddeler/Developer/run/Homestead/scripts/homestead.rb:169:in `+': no implicit conversion of nil into String (TypeError)
from /Users/shaddeler/Developer/run/Homestead/scripts/homestead.rb:169:in `block (2 levels) in configure'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/plugins/kernel_v2/config/vm_provisioner.rb:72:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/plugins/kernel_v2/config/vm_provisioner.rb:72:in `add_config'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/plugins/kernel_v2/config/vm.rb:324:in `provision'
from /Users/shaddeler/Developer/run/Homestead/scripts/homestead.rb:168:in `block in configure'
from /Users/shaddeler/Developer/run/Homestead/scripts/homestead.rb:157:in `each'
from /Users/shaddeler/Developer/run/Homestead/scripts/homestead.rb:157:in `configure'
from /Users/shaddeler/Developer/run/Homestead/Vagrantfile:30:in `block in <top (required)>'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/config/v2/loader.rb:37:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/config/v2/loader.rb:37:in `load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/config/loader.rb:113:in `block (2 levels) in load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/config/loader.rb:107:in `each'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/config/loader.rb:107:in `block in load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/config/loader.rb:104:in `each'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/config/loader.rb:104:in `load'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/vagrantfile.rb:28:in `initialize'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/environment.rb:746:in `new'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/environment.rb:746:in `vagrantfile'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/environment.rb:492:in `host'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/environment.rb:214:in `block in action_runner'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/action/runner.rb:33:in `call'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/action/runner.rb:33:in `run'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/environment.rb:479:in `hook'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant/environment.rb:728:in `unload'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/bin/vagrant:177:in `ensure in <main>'
from /opt/vagrant/embedded/gems/gems/vagrant-1.8.6/bin/vagrant:177:in `<main>'
I enfaced this error while vagrant up
I had this problem too. Instead of a wrong indentation, I accidentally added another dash ( - ) to my Homestead.yaml file.
For example, this is the incorrect one:
- map: testing.khc.my
- to: /home/vagrant/code/testing/public
The correct one is this:
- map: testing.khc.my
to: /home/vagrant/code/testing/public
Hope this help everyone in the future.
I got this error too and it's a real pain. The source of the problem is a wrong indentation in the Homestead.yaml file. Check if you're using spaces or tabs.

Capistrano 3 deployment is broken

my capistrano3 deployment is broken. I really don't know why, it was like yesterday it works and today it doesn't. Please have a look at the error it gives me:
cap aborted!
Errno::ENOENT: No such file or directory # rb_file_s_stat - /tmp/PROJECT-0d9226685f71.tar.gz
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-scp-1.2.1/lib/net/scp/upload.rb:117:in `stat'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-scp-1.2.1/lib/net/scp/upload.rb:117:in `set_current'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-scp-1.2.1/lib/net/scp/upload.rb:24:in `upload_start_state'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-scp-1.2.1/lib/net/scp.rb:369:in `block (3 levels) in start_command'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/channel.rb:324:in `call'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/channel.rb:324:in `process'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/session.rb:223:in `block in preprocess'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/session.rb:223:in `each'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/session.rb:223:in `preprocess'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/session.rb:206:in `process'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/session.rb:170:in `block in loop'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/session.rb:170:in `loop'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/session.rb:170:in `loop'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-ssh-3.0.2/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/net-scp-1.2.1/lib/net/scp.rb:284:in `upload!'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/sshkit-1.8.1/lib/sshkit/backends/netssh.rb:34:in `block in upload!'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/sshkit-1.8.1/lib/sshkit/backends/netssh.rb:141:in `with_ssh'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/sshkit-1.8.1/lib/sshkit/backends/netssh.rb:33:in `upload!'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/capistrano-scm-gitcopy-0.1.2/lib/capistrano/tasks/gitcopy.rake:79:in `block (4 levels) in <top (required)>'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:64:in `within'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/capistrano-scm-gitcopy-0.1.2/lib/capistrano/tasks/gitcopy.rake:77:in `block (3 levels) in <top (required)>'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:15:in `instance_exec'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/sshkit-1.8.1/lib/sshkit/backends/abstract.rb:15:in `run'
/Users/USER/.rvm/gems/ruby-2.2.0#SERVER/gems/sshkit-1.8.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => gitcopy:create_release
The deploy has failed with an error: No such file or directory # rb_file_s_stat - /tmp/PROJECT-0d9226685f71.tar.gz
** Invoke deploy:failed (first_time)
** Execute deploy:failed
I don't know what it is. Maybe some capistrano bug or a bug in my configs? Let me know if you need more informations
Answer is following:
https://github.com/xuwupeng2000/capsitrano-scm-gitcopy#installation
Finally, DO NOT ADD require 'capistrano/gitcopy' to Capfile because capistrano/setup already loads the scm module with the :scm value you specified.

Ruby syntax in chef recipe

Guys I have no clue in ruby but forced to play around with a chef recipe. Can someone help me with a syntax issue ?
These line is causing problems when I run the recipe
old_configs = node["monitoring"]["configs"] || []
And the exception is :
NoMethodError: undefined method `[]' for nil:NilClass /var/chef/cache/cookbooks/collectd/recipes/default.rb:100:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/cookbook_version.rb:237:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/run_context.rb:151:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/run_context/cookbook_compiler.rb:139:in `block in compile_recipe
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/run_context/cookbook_compiler.rb:137:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/run_context/cookbook_compiler.rb:137:in `compile_recipes'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/run_context/cookbook_compiler.rb:74:in `compile'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/run_context.rb:86:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/client.rb:249:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/client.rb:492:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/client.rb:199:in `block in run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/client.rb:193:in `fork'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/client.rb:193:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/application.rb:183:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/application/client.rb:302:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/application/client.rb:294:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/application/client.rb:294:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/application.rb:66:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/bin/chef-client:26:in `<top (required)>'
This is probably caused by the fact that the node "monitoring" attribute does not exist, you should first check that node["monitoring"] exists, before trying to lookup node["monitoring"]["configs"]
The simple way to do it would be:
if node["monitoring"]
old_configs = node["monitoring"]["configs"] || []
end

Problems with character encoding in Resque

I have a series of JSON messages that I need to process and I've run into some trouble with character encodings. I retrieve this message from a RabbitMQ queue like so:
#data = []
#queue.pop do |metadata, payload|
parsed_message = JSON.parse(payload)
#data << parsed_message
end
I then process them using Resque and enqueue them like so:
Resque.enqueue(Worker, #data)
When I run the worker it throws this error:
** [16:06:13 2012-09-14] 5375: Error reserving job: #<Encoding::InvalidByteSequenceError: "\xC3" on US-ASCII>
** [16:06:13 2012-09-14] 5375: /usr/local/lib/ruby/1.9.1/json/common.rb:148:in `encode'
/usr/local/lib/ruby/1.9.1/json/common.rb:148:in `initialize'
/usr/local/lib/ruby/1.9.1/json/common.rb:148:in `new'
/usr/local/lib/ruby/1.9.1/json/common.rb:148:in `parse'
/usr/local/lib/ruby/gems/1.9.1/gems/multi_json-1.3.6/lib/multi_json/adapters/json_common.rb:7:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/multi_json-1.3.6/lib/multi_json.rb:93:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/helpers.rb:38:in `decode'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque.rb:149:in `pop'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/job.rb:100:in `reserve'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque.rb:303:in `reserve'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/worker.rb:209:in `block in reserve'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/worker.rb:207:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/worker.rb:207:in `reserve'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/worker.rb:136:in `block in work'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/worker.rb:133:in `loop'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/worker.rb:133:in `work'
/usr/local/lib/ruby/gems/1.9.1/gems/resque-1.22.0/lib/resque/tasks.rb:36:in `block (2 levels) in <top (required)>'
/usr/local/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/usr/local/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/usr/local/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/usr/local/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/usr/local/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/usr/local/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/usr/local/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/local/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/usr/local/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/usr/local/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/usr/local/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/usr/local/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/usr/local/bin/rake:32:in `<main>'
rake aborted!
I've wrapped all the code in the perform function from the worker in a begin/rescue block, to try to catch the exception but to no avail which leads me to think that it's from inside Resque somewhere.
I've tried enqueueing the Resque worker with the raw data and then parse it inside the worker into JSON and setting an UTF-8 encoding:
raw_data.each do |msg|
msg = msg.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "")
parsed_msg = JSON.parse(msg) rescue nil
next if parsed_msg.nil?
parsed_data << parsed_msg
end
and I still get the same error.
It's not always the same character, sometimes it's \xC2 or \xD8 if I remember correctly
Any ideas?
Is it possible the file encoding is incorrect?
Try inserting:
# encoding: UTF-8
at the top of the relevant ruby source files. This is one of the most obnoxious things in Ruby 1.9.

Resources