Reloading ohai during compilation?


#1

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

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?


#2

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