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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -