Chris F
Chris F

Reputation: 16685

How can I fix ERROR: "\xC3" on US-ASCII when bootstrapping chef-client?

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

Upvotes: 3

Views: 3029

Answers (2)

kenorb
kenorb

Reputation: 166399

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.

Upvotes: 7

coderanger
coderanger

Reputation: 54211

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

Upvotes: 0

Related Questions