3

I have a chef server and client VMs running RHEL 5.10 with the latest patches. When I try to boostrap the chef-client with

knife bootstrap nodename -N nodename -x root -P password

I get the following error, which prevents my automatic attributes to be populated on the server.

nodename Converging 0 resources
nodename
nodename Running handlers:
nodename [2014-07-25T14:46:40-04:00] ERROR: Running exception handlers
nodename Running handlers complete
nodename 
nodename [2014-07-25T14:46:40-04:00] ERROR: Exception handlers complete
nodename [2014-07-25T14:46:40-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
nodename Chef Client failed. 0 resources updated in 3.383781 seconds
nodename [2014-07-25T14:46:40-04:00] ERROR: "\xC3" on US-ASCII
nodename [2014-07-25T14:46:40-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Here's the referred stacktrace

Generated at 2014-07-25 15:01:29 -0400
Encoding::InvalidByteSequenceError: "\xC3" on US-ASCII
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418:in `encode'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418:in `to_json'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418:in `to_json'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418:in `to_json'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418:in `to_json'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418:in `to_json'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418:in `to_json'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/json_compat.rb:102:in `to_json'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/http/json_input.rb:34:in `handle_request'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/http.rb:217:in `block in apply_request_middleware'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/http.rb:215:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/http.rb:215:in `inject'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/http.rb:215:in `apply_request_middleware'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/http.rb:139:in `request'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/http.rb:116:in `put'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:523:in `save'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/client.rb:287:in `save_updated_node'

Here is /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.8/lib/chef/node.rb:418

# Serialize this object as a hash
def to_json(*a)
  for_json.to_json(*a) # this is line 418
end

This the output of the locale command on my chef-client running RHEL 5.10

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

NOTE: I only get the error when boot-strapping a fresh OS with the chef-client on my Windows 7 chef workstation running cygwin. If I bootstrap from a RHEL-based workstation, I don't get the error

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • Any idea where the 0xC3 is coming from or what it is supposed to be? It is `Ã` in ISO-8859-1, `Г` in Windows-CP1251, etc. – mu is too short Jul 25 '14 at 19:51
  • No, I have no idea. My workstation, where I'm running the bootstrap command on, is a Windows 7 64-bit, with cygwin. – Chris F Jul 25 '14 at 20:29
  • `C3` is also the first byte of the UTF-8 encoding for all high Latin1 characters (U+00A0 through U+00FF). That seems like a more likely source… –  Jul 25 '14 at 20:42
  • possible duplicate of [Hudsion/Jenkins with Ruby 1.9.3p125 Cucumber does not succeed (\`encode': "\xD8" on US-ASCII (Encoding::InvalidByteSequenceError))](http://stackoverflow.com/questions/12464023/hudsion-jenkins-with-ruby-1-9-3p125-cucumber-does-not-succeed-encode-xd8) – kenorb Mar 20 '15 at 19:27

2 Answers2

7

This can be resolved by forcing your UTF-8 encoding, so check your locale settings and set the following:

# encoding: utf-8
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8

If this won't help, try the following lines in shell:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

just before: bundle exec knife solo cook root@.

To check which UTF-8 locale is supported by terminal, run:

locale -a | grep "UTF-8"

as it can be C.UTF-8 instead.

This error usually happening with older Chef versions, but in in Chef Client 12 UTF-8 will be forced by Chef it-self to avoid issues like this.

See also: UnicodeEncodeError: 'ascii' codec can't encode character.

kenorb
  • 155,785
  • 88
  • 678
  • 743
0

Usually the culprit is one of the ohai plugins gathering data from the system. The quick fix is to disable the offending plugin.

coderanger
  • 52,400
  • 4
  • 52
  • 75