# Set node value from script output

**URL:** <https://discourse.chef.io/t/set-node-value-from-script-output/1897>\
**Category:** Chef Infra (archive)\
**Created:** [June 27, 2011, 8:46pm UTC](https://discourse.chef.io/t/set-node-value-from-script-output/1897 "2011-06-27T20:46:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Drobnak](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Matthew\_Drobnak](https://discourse.chef.io/u/Matthew_Drobnak)\
**Post date:** [June 27, 2011, 8:46pm UTC](https://discourse.chef.io/t/set-node-value-from-script-output/1897/1 "2011-06-27T20:46:52Z")

</div>

I need the output of a script to set a node value, from inside a cookbook. How would one do this?

Thanks.

-Matt

---

<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:** [June 27, 2011, 8:55pm UTC](https://discourse.chef.io/t/set-node-value-from-script-output/1897/2 "2011-06-27T20:55:38Z")

</div>

On Jun 27, 2011, at 1:46 PM, Matthew Drobnak wrote:

> I need the output of a script to set a node value, from inside a cookbook. How would one do this?

You will have to call Chef::ShellOut (or something similar) from within a ruby\_block resource.

--Noah

---

<div class="post-metadata">

**Author:** ![John\_Alberts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_alberts/32/293_2.png) [@John\_Alberts](https://discourse.chef.io/u/John_Alberts)\
**Post date:** [June 27, 2011, 10:25pm UTC](https://discourse.chef.io/t/set-node-value-from-script-output/1897/3 "2011-06-27T22:25:52Z")

</div>

Something like the following should work as well.

node[:myattribute] = %x[/usr/bin/myscript]

John

On Mon, Jun 27, 2011 at 3:55 PM, Noah Kantrowitz [noah@coderanger.net](mailto:noah@coderanger.net)wrote:

> On Jun 27, 2011, at 1:46 PM, Matthew Drobnak wrote:
> 
> > I need the output of a script to set a node value, from inside a  
> > cookbook. How would one do this?
> 
> You will have to call Chef::ShellOut (or something similar) from within a  
> ruby\_block resource.
> 
> --Noah

--  
John Alberts

---

<div class="post-metadata">

**Author:** ![Matthew\_Drobnak](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Matthew\_Drobnak](https://discourse.chef.io/u/Matthew_Drobnak)\
**Post date:** [June 27, 2011, 10:30pm UTC](https://discourse.chef.io/t/set-node-value-from-script-output/1897/4 "2011-06-27T22:30:01Z")

</div>

Would that persist in the chef db? Or would I have to set it each time?

Thanks for the help.

-Matt  
On Jun 27, 2011, at 6:25 PM, John Alberts wrote:

Something like the following should work as well.

node[:myattribute] = %x[/usr/bin/myscript]

John

On Mon, Jun 27, 2011 at 3:55 PM, Noah Kantrowitz \<[noah@coderanger.net](mailto:noah@coderanger.net)[mailto:noah@coderanger.net](mailto:noah@coderanger.net)\> wrote:

On Jun 27, 2011, at 1:46 PM, Matthew Drobnak wrote:

> I need the output of a script to set a node value, from inside a cookbook. How would one do this?

You will have to call Chef::ShellOut (or something similar) from within a ruby\_block resource.

--Noah

--  
John Alberts

---

<div class="post-metadata">

**Author:** ![Matthew\_Drobnak](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Matthew\_Drobnak](https://discourse.chef.io/u/Matthew_Drobnak)\
**Post date:** [June 27, 2011, 10:43pm UTC](https://discourse.chef.io/t/set-node-value-from-script-output/1897/5 "2011-06-27T22:43:49Z")

</div>

I think I've found it in the wiki:

node.set['myattribute'] = %x[/usr/bin/myscript]

-Matt

On Jun 27, 2011, at 6:30 PM, Matthew Drobnak wrote:

Would that persist in the chef db? Or would I have to set it each time?

Thanks for the help.

-Matt  
On Jun 27, 2011, at 6:25 PM, John Alberts wrote:

Something like the following should work as well.

node[:myattribute] = %x[/usr/bin/myscript]

John

On Mon, Jun 27, 2011 at 3:55 PM, Noah Kantrowitz \<[noah@coderanger.net](mailto:noah@coderanger.net)[mailto:noah@coderanger.net](mailto:noah@coderanger.net)\> wrote:

On Jun 27, 2011, at 1:46 PM, Matthew Drobnak wrote:

> I need the output of a script to set a node value, from inside a cookbook. How would one do this?

You will have to call Chef::ShellOut (or something similar) from within a ruby\_block resource.

--Noah

--  
John Alberts
