# Reloading ohai during compilation?

**URL:** <https://discourse.chef.io/t/reloading-ohai-during-compilation/4460>\
**Category:** Chef Infra (archive)\
**Created:** [September 16, 2013, 5:22pm UTC](https://discourse.chef.io/t/reloading-ohai-during-compilation/4460 "2013-09-16T17:22:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Herot](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/eric_herot/32/84_2.png) [@Eric\_Herot](https://discourse.chef.io/u/Eric_Herot)\
**Post date:** [September 16, 2013, 5:22pm UTC](https://discourse.chef.io/t/reloading-ohai-during-compilation/4460/1 "2013-09-16T17:22:20Z")

</div>

So if I have code like this:

user “deploy”

file “#{node[‘etc’][‘passwd’][‘deploy’][‘dir’]}/.somefile” do  
source "somefile"  
end

How do I make it work without giving me an error like this one:

## ArgumentError

You must supply a name when declaring a dir resource

… and without “assuming” that deploy’s home directory is always going to be /home/deploy?

I tried using this trick:

[https://tickets.opscode.com/browse/CHEF-1507](https://tickets.opscode.com/browse/CHEF-1507)

but it doesn’t seem to get run during the compile phase at all (which makes sense). Is there a way around this problem? Do I have to force all users to get created during the compile phase?

---

<div class="post-metadata">

**Author:** ![Bryan\_McLellan1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bryan_mclellan1/32/426_2.png) [@Bryan\_McLellan1](https://discourse.chef.io/u/Bryan_McLellan1)\
**Post date:** [September 17, 2013, 3:31am UTC](https://discourse.chef.io/t/reloading-ohai-during-compilation/4460/2 "2013-09-17T03:31:10Z")

</div>

The error you included doesn’t seem to match the example resource you  
provided, but I think I can gather what you’re trying to do. There’s a  
number of tricks required here.

1. Tell Ruby to close the passwd file so ohai can pick up your changes
2. Reload the ohai etc plugin after the creation of the user
3. Use the delayed attribute evaluation (lazy) so we don’t evaluate  
the attribute before it exists (CHEF-3731)

Note if you’re dealing with LDAP or modifying nsswitch.conf for  
anything, you’ve got another problem, and it’s name is glibc  
(CHEF-3780).

user “btm-test” do  
supports :manage\_home =\> true  
home "/home/btm-test"  
end

ruby\_block “close the passwd file in Ruby” do  
block do  
Etc.endpwent  
end  
end

ohai “reload passwd plugin” do  
action :reload  
plugin "passwd"  
end

file “foo-btm” do  
path lazy { “#{node[‘etc’][‘passwd’][‘btm-test’][‘dir’]}/foo” }  
content "words words words"  
end

–  
Bryan McLellan | opscode | technical program manager, open source  
© 206.607.7108 | (t) @btmspox | (b) [http://blog.loftninjas.org](http://blog.loftninjas.org)
