ruby - Chef update certain user's .bashrc -


i'm trying update users .bashrc java_home environment variable after installing jdk. strange error don't understand. here's block of code in question.

node['etc']['passwd'].each |user, data|   only_if {data['uid'] > 9000}   jdk_dir_array = dir.entries('/usr/java/').select {|entry| file.directory? file.join('/usr/java/',entry) , !(entry =='.' || entry == '..') }   jdk_dir_name = jdk_dir_array.shift   file = chef::util::fileedit.new("#{data['dir']}/.bashrc")   file.search_file_replace( /java_home=.*/,"java_home=/usr/java/#{jdk_dir_name}")   file.write_file end 

the error i'm getting this:

nomethoderror ------------- no resource or method named `only_if' `chef::recipe "install_jdk"' 

i don't understand why thinks "only_if" method of recipe when declare inside of node.each block.

i should point out if put in ruby_block , hardcode path single user's home directory code works expected. i'm trying update multiple users , that's i'm stumped.

only_if method use on resource, not in either recipe or inside block of ruby_block. want more like:

node['etc']['passwd'].each |user, data|   ruby_block "edit #{user} bashrc"   only_if { data['uid'] > 9000 }   block     jdk_dir_array = dir.entries('/usr/java/').select {|entry| file.directory? file.join('/usr/java/',entry) , !(entry =='.' || entry == '..') }     jdk_dir_name = jdk_dir_array.shift     file = chef::util::fileedit.new("#{data['dir']}/.bashrc")     file.search_file_replace( /java_home=.*/,"java_home=/usr/java/#{jdk_dir_name}")     file.write_file   end end 

i recommend not doing though. check out line cookbook more refined way approach this, or consider having chef manage whole file via template resource.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -