How to initiate chef-client command from a recipe

I am running a recipe which has the following resource

execute 'bootstrap' do
  command 'chef-client -j /etc/chef/prod/first-boot.json'
end

As you can see I am trying to run another chef-client command from within another chef-client run. How can achieve this. This is the requirement so I cannot change how this resource works.

Is the first recipe in solo or client?

Client. Basically I am bootstrapping the node using knife bootstrap command with a run-list set to the 2nd recipe.

That is not supported. We have a locking system specifically to prevent it. You can do it internally though, read in the JSON and set the node’s run list. Remember it won’t take effect until the next run though so make sure the first run configures some kind of daemon or cron job.

The chef-client command is for bootstrapping a node. Is there any other way than chef-client way to bootstrap a node from a recipe. My recipe works fine when I use chef-solo

Or if there are some steps which simulate a bootstrap that would help. I can automate it via a recipe. I need to write a recipe which can bootstrap/simulate a bootstrap.

By definition a bootstrap means installing Chef, setting up a configuration, and creating client credentials. If Chef is already running, even under solo, the first two steps are done, so it’s then just a matter of creating client credentials. And for security reasons we recommend using knife bootstrap for that, because it uses the actual workstation user credentials for the create, rather than the older validation key system which is a security nightmare.

Well the node is already bootstrapped under 1 organisation so you are right chef client is already there on the node. I can see the node on chef-manage . What I am trying to achieve is bootstrapping it to one more organisation. So just by creating client creds I dont think the node will be registered under the 2nd org?

@coderanger any pointers for this? I need to bootstrap an already bootstrapped node to another organisation with a new run list.

It’s worth mentioning at the outset that you’re trying to switch a node to a new server as that’s very relevant to the conversation. In short, there is nothing special for switching nodes from one server to another - you could write a custom bootstrap template to take care of this and RE-bootstrap the nodes but trying to take care of this via Chef is probably the wrong way to go about it.