# Q about accessing variables from other recipe and splitting attribute files by folders

**URL:** <https://discourse.chef.io/t/q-about-accessing-variables-from-other-recipe-and-splitting-attribute-files-by-folders/5899>\
**Category:** Chef Infra (archive)\
**Created:** [November 7, 2014, 2:22pm UTC](https://discourse.chef.io/t/q-about-accessing-variables-from-other-recipe-and-splitting-attribute-files-by-folders/5899 "2014-11-07T14:22:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniil\_S](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Daniil\_S](https://discourse.chef.io/u/Daniil_S)\
**Post date:** [November 7, 2014, 2:22pm UTC](https://discourse.chef.io/t/q-about-accessing-variables-from-other-recipe-and-splitting-attribute-files-by-folders/5899/1 "2014-11-07T14:22:29Z")

</div>

Hello.

I would be grateful if you answer a couple questions.

1. Is it possible to access variables defined in one recipe from the other? For example:

cookbooks/cookbook\_name/default.rb:  
foo = :bar

cookbooks/cookbook\_name/somerecipe.rb:  
template syspath do  
source repopath  
variables( :params =\> foo )  
end

1. Is it possible to load attributes from files located in subdirectory of attribute folder? For example:

## cookbooks/ |-cookbook\_name/ ||-attributes/ ||-default.rb |||-attribute\_folder1/ ||||-one\_more\_attribute\_file.rb |||-attribute\_folder2/ ||||-one\_more\_attribute\_file.rb

Thanks in advance, Daniil.

---

<div class="post-metadata">

**Author:** ![Daniil\_S](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@Daniil\_S](https://discourse.chef.io/u/Daniil_S)\
**Post date:** [November 10, 2014, 6:05am UTC](https://discourse.chef.io/t/q-about-accessing-variables-from-other-recipe-and-splitting-attribute-files-by-folders/5899/2 "2014-11-10T06:05:17Z")

</div>

# Correction of the 1st question: ‘default’ recipe contains ‘include’ of ‘somerecipe’:

cookbooks/cookbook\_name/default.rb:  
foo = :bar  
include ‘cookbook\_name::somerecipe’

# cookbooks/cookbook\_name/somerecipe.rb: Chef::Log.info(foo) template syspath do source repopath variables( :params =\> foo ) end

## So I think there certainly should be some way to access variable.

Thanks in advance, Daniil.

```
 пятница, 7 ноября 2014 17:22 Daniil S <daniil_sb@yahoo.com> писал(а):

```

Hello.

I would be grateful if you answer a couple questions.

1. Is it possible to access variables defined in one recipe from the other? For example:

cookbooks/cookbook\_name/default.rb:  
foo = :bar

cookbooks/cookbook\_name/somerecipe.rb:  
template syspath do  
source repopath  
variables( :params =\> foo )  
end

1. Is it possible to load attributes from files located in subdirectory of attribute folder? For example:

## cookbooks/ |-cookbook\_name/ ||-attributes/ ||-default.rb |||-attribute\_folder1/ ||||-one\_more\_attribute\_file.rb |||-attribute\_folder2/ ||||-one\_more\_attribute\_file.rb

Thanks in advance, Daniil.
