简体   繁体   中英

chef-client failing as node_name not present in client.rb

I followed a tutorial here to bootstrap and register a node to chef server. The instance is in autoscaling group which is why I opted this method for bootstrapping. Scenario is - I am using client.rb, validation.pem, trusted_certs from s3 to newly launched instance via userdata.

client.rb

log_location     STDOUT
chef_server_url  "https://chef.myserver.org/organizations/org"
validation_client_name "org-validator"
# Using default node name (fqdn)
trusted_certs_dir "/etc/chef/trusted_certs"

After downloading required files following command get executed to run chef-client with $INSTANCE_ID as node_name.

chef-client -N $INSTANCE_ID -j /etc/chef/first-boot.json

The initial bootstrapping is successful and the node gets registered to chef-server with instance-id as node-name but when running subsequent chef-client, it fails with the error:

ERROR: 401 "Unauthorized" 

This is due to the node_name not present in client.rb. How can I make the entry of node_name in client.rb during the very first chef-client run?

This is generally handled in the userdata script or config, a la echo "node_name '$HOSTNAME'" >>/etc/chef/client.rb . The specifics can vary depending on your naming scheme, sometimes you'll make some string edits to $HOSTNAME or use a different name entirely. This isn't strictly required, but without a name in the config file, Chef uses whatever the current FQDN of the system is, and it sounds like something in the initial Chef run changes the FQDN. Another option is to just not do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM