0

I am trying to set up a Chef node using Vagrant, but running in to an error with the bootstrap command. I am following the tutorial on learn.chef.io

My Chef server is setup on EC2, and works great. I can successfully upload cookbooks from my workstation to the server itself.

However, when running the following bootstrap command from my workstation to setup a node:

knife bootstrap localhost --ssh-port 2222 --ssh-user vagrant --sudo --identity-file /Users/Shivam/.vagrant/machines/default/virtualbox/private_key --node-name node1-ubuntu --run-list 'recipe[learn_chef_apache2]'

I get the following error.

Creating new client for node1-ubuntu
Creating new node for node1-ubuntu
Connecting to localhost
localhost -----> Existing Chef installation detected
localhost Starting the first Chef Client run...
localhost Starting Chef Client, version 13.2.20
localhost
localhost ================================================================================
localhost Chef encountered an error attempting to load the node data for "node1-ubuntu"
localhost ================================================================================
localhost
localhost Authentication Error:
localhost ---------------------
localhost Failed to authenticate to the chef server (http 401).
localhost The request failed because your clock has drifted by more than 15 minutes.
localhost Syncing your clock to an NTP Time source should resolve the issue.
localhost
localhost System Info:
localhost ------------
localhost chef_version=13.2.20
localhost ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
localhost program_name=chef-client worker: ppid=17409;start=22:48:40;
localhost executable=/opt/chefdk/bin/chef-client
localhost
localhost
localhost Running handlers:
localhost [2018-04-28T22:48:42+00:00] ERROR: Running exception handlers
localhost Running handlers complete
localhost [2018-04-28T22:48:42+00:00] ERROR: Exception handlers complete
localhost Chef Client failed. 0 resources updated in 01 seconds
localhost [2018-04-28T22:48:42+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
localhost [2018-04-28T22:48:42+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
localhost [2018-04-28T22:48:42+00:00] ERROR: 401 "Unauthorized"
localhost [2018-04-28T22:48:42+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

This is what the stack trace output is on my Vagrant virtual machine.

Generated at 2018-04-28 22:33:52 +0000
Net::HTTPServerException: 401 "Unauthorized"
/opt/chefdk/embedded/lib/ruby/2.4.0/net/http/response.rb:122:in `error!'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/http.rb:152:in `request'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/http.rb:131:in `post'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/api_client/registration.rb:96:in `create'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/api_client/registration.rb:87:in `create_or_update'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/api_client/registration.rb:58:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:666:in `register'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:267:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:291:in `block in fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:244:in `block in run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:232:in `run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:469:in `sleep_then_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:458:in `block in interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `loop'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:441:in `run_application'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:59:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:263:in `load'
/usr/bin/chef-client:263:in `<main>'
~

This is what my knife.rb looks like on my workstation.

current_dir = File.dirname(__FILE__)
log_level                 :info
log_location              STDOUT
node_name                 "chefadmin"
client_key                "#{current_dir}/chefadmin.pem"
chef_server_url           "https://ec2-11-90-25-181.compute-1.amazonaws.com/organizations/4thcoffee"
cookbook_path             ["#{current_dir}/../cookbooks"]

I have followed the advice here Chef bootstrap giving 401 unauthorized with no luck.

Probably missing something straightforward. Thanks in advance!

ShivamD
  • 101
  • 1

1 Answers1

0

Your error message says following:

The request failed because your clock has drifted by more than 15 minutes. Syncing your clock to an NTP Time source should resolve the issue.

Have you tried syncing your clock?

AlexD
  • 8,179
  • 2
  • 28
  • 38