how to replace :
export JAVA_HOME=${JAVA_HOME}
with :
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::") in
hadoop-env.sh using
RUBY_BLOCK resource in CHEF
replacements should be simple replacements. For something this complex you should grab the entire file as it currently exists and use it as an ERB template with your changes inside of it, even if that means not putting any variables inside of it similar to what Tensibai said in comment