-1

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
rajpalla
  • 35
  • 5
  • ruby_block "edit hadoop-env sh" do block do file = Chef::Util::FileEdit.new("/usr/local/hadoop/etc/hadoop/hadoop-env.sh") file.search_file_replace_line(export JAVA_HOME=\$\{JAVA_HOME}, export JAVA_HOME=\$\(readlink -f /usr/bin/java | sed "s:bin/java::")) file.write_file end end – rajpalla Dec 22 '16 at 13:03
  • What are you trying to do with this comment ? Editing a file is strangly discouraged with chef, it's the path to shoot yourself in the foot on mid term. Use a template to manage the whole file. – Tensibai Dec 22 '16 at 15:20
  • can tell me how we do it – rajpalla Dec 22 '16 at 15:28
  • 1
    ... `template "/usr/local/hadoop/etc/hadoop/hadoo‌​p-env.sh" do \n source hadoop-env.sh.erb end` And you take the file from an existing install to paste it as a template in `templates/defaults/hadoop-env.sh.erb`. See the [documentation](https://docs.chef.io/resource_template.html) and https://learn.chef.io also – Tensibai Dec 22 '16 at 15:30

1 Answers1

0

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

Marc Young
  • 3,854
  • 3
  • 18
  • 22