# How to initiate chef-client command from a recipe

**URL:** <https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899>\
**Category:** Chef Infra (archive)\
**Created:** [November 9, 2017, 6:20am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899 "2017-11-09T06:20:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![akajain](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@akajain](https://discourse.chef.io/u/akajain)\
**Post date:** [November 9, 2017, 6:20am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/1 "2017-11-09T06:20:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [November 9, 2017, 6:45am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/2 "2017-11-09T06:45:04Z")

</div>

Is the first recipe in solo or client?

---

<div class="post-metadata">

**Author:** ![akajain](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@akajain](https://discourse.chef.io/u/akajain)\
**Post date:** [November 9, 2017, 6:46am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/3 "2017-11-09T06:46:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [November 9, 2017, 6:52am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/4 "2017-11-09T06:52:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![akajain](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@akajain](https://discourse.chef.io/u/akajain)\
**Post date:** [November 9, 2017, 7:11am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/5 "2017-11-09T07:11:26Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![akajain](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@akajain](https://discourse.chef.io/u/akajain)\
**Post date:** [November 9, 2017, 7:22am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/6 "2017-11-09T07:22:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [November 9, 2017, 8:16am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/7 "2017-11-09T08:16:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![akajain](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@akajain](https://discourse.chef.io/u/akajain)\
**Post date:** [November 9, 2017, 8:21am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/8 "2017-11-09T08:21:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![akajain](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@akajain](https://discourse.chef.io/u/akajain)\
**Post date:** [November 13, 2017, 8:23am UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/9 "2017-11-13T08:23:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cheeseplus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/cheeseplus/32/960_2.png) [@cheeseplus](https://discourse.chef.io/u/cheeseplus)\
**Post date:** [November 14, 2017, 1:06pm UTC](https://discourse.chef.io/t/how-to-initiate-chef-client-command-from-a-recipe/11899/10 "2017-11-14T13:06:57Z")

</div>

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.
