slayedbylucifer
slayedbylucifer

Reputation: 23492

"chef-client -j" is not running as expected

I am trying to bootstrap a node on its own and run the getting-started recipe on first boot. Everything seems to work fine except that the actual recipe is never run.

Here is my script which is triggered by rc.local:

#!/bin/bash

wget http://<some_IP_Address>/chef-11.6.0-1.el6.x86_64.rpm -P /var/tmp/
rpm -ivh /var/tmp/chef-11.6.0-1.el6.x86_64.rpm
mkdir -p /etc/chef
cd /etc/chef
wget http://<some_IP_Address>/chef-validator.pem
mv chef-validator.pem validation.pem

cat > client.rb << EOL
log_level        :auto
log_location     STDOUT
chef_server_url  "MY_CHEF_SERVER_FQDN"
validation_client_name "chef-validator"
EOL

cat > /etc/chef/firstboot.json << EOL
{"run_list": ["recipe[getting-started]"]}
EOL

chef-client -j /etc/chef/firstboot.json

Once the node is booted up, I see that the node gets registered with the chef server however the getting-started recipe which was specified in firstboot.json along with chef-client -j on the last line of my script does not get triggered.

It acts like only chef-client is being triggered and not chef-client -j /etc/chef/firstboot.json

If I look at my workstation, I see that this recipe is added to the node's run_list as well, just that it is not yet executed.

Here is the command output from my chef workstation for the node which was bootstrapped:

$ knife node show node_name.domain.com --run-list
node_name.domain.com:
  run_list: recipe[getting-started]

QUESTION: Could you tell me what I could be missing here? why chef-client is not able to run whatever mentioned in firstboot.json.

UPDATE: If I run chef-client -j /etc/chef/firstboot.json manually, then it does the job. So it seems like something is wrong with the rc.local invoke. It is running only chef-client even if I have mentioned chef-client -j /etc/chef/firstboot.json

Thanks.

Upvotes: 1

Views: 5591

Answers (2)

slayedbylucifer
slayedbylucifer

Reputation: 23492

The "getting-started" recipe is supposed to create "chef-getting-started.txt" under user's home directory. It indeed was creating that file under "/".

But anyway, It validates my thinking around how to bootstrap an instance from autoscalling perspective.

Upvotes: 0

Draco Ater
Draco Ater

Reputation: 21206

Instead of

cat > /etc/chef/firstboot.json << EOL
{"run_list": ["recipe[getting-started]"]}
EOL

chef-client -j /etc/chef/firstboot.json

in your script, try:

chef-client -o 'getting-started'

Upvotes: 2

Related Questions