Ask Your Question
0

replace strings in a template file

asked 2015-05-04 17:04:32 -0500

R gravatar image

updated 2015-09-01 16:48:20 -0500

I am trying to automate Oracle Installation which includes parsing and altering the response file (.rsp). Here is a snippet of how it looks:

  MW_HOME=/devops/oracle/dev/11_1_1_7

So basically dev = Environment name, 11_1_1_7 is the version number. These values change depending on the hostname.

I am thinking of using regsubst for replacing the value of environment name and version number. The values will be passed as a variable to the class. My questions are:

  1. Where do I save the .rsp file (under templates folder) or anywhere on the disk.
  2. How do I read the .rsp file?
  3. how we save the variables in the .rsp file so that it can take values from the variables pased to the class. is it like this:

    MW_HOME=/devops/oracle/$environment_name/$version_number.
    

Please let me know.

Thanks R

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-05-04 17:32:15 -0500

JohnsonEarls gravatar image

updated 2015-05-05 07:23:20 -0500

If every system has identical response files except for that line, I think your best bet is to make the default response file into a template (which would get stored in the module's templates/ directory), and then use the template variable substitution to fill in the values:

MW_HOME=/devops/oracle/<%= @environment_name %>/<%= @version_number %>

To use this in the Oracle installer, use a file and exec resource, something like this:

file { "/path/to/install-oracle.rsp":
    ensure => file ,
    content => template("${module_name}/install-oracle.erb")
} ->
exec { "Install Oracle":
    command => "/path/to/runInstaller -silent -response /path/to/install-oracle.rsp -invPtrLoc /etc/oraInst.loc" ,
    unless => test -x /path/to/binary/that/gets/installed
}

Replace the various /path/to/... with actual directory names. This will create the response file (it will need to be in some "permanent" location on the local system, since Puppet will want it to exist every time), then will run the installer unless whatever binary the installer creates already exists.

edit flag offensive delete link more

Comments

Thanks a ton thats exactly what I am looking for. Yes the response files will be same except for that line. How do I verify the output. Is there a way I can actually verify the output file (with the values written in it) . Thank you thank you thanks a lot again.

R gravatar imageR ( 2015-05-04 18:37:26 -0500 )edit

The puppetlabs docs give a way to test for syntax: erb -P -x -T '-' mytemplate.erb | ruby -c however, that won't show the replacement values. You would have to write a short ruby program and use the 'erb' ruby library to test the replacement values.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-05-04 18:58:01 -0500 )edit

I have this defined in the template file MW_HOME=/devops/oracle/<%= @environment_name %>/<%= @version_number.to_s %>. I get this error when I check for the syntax " unexpected tIVAR, expecting ')' ...out.concat(( @environment_name @version_number.to_s).to_s; _erbout. Thanks

R gravatar imageR ( 2015-05-04 19:29:00 -0500 )edit

I just created a file with just that line ((MW_HOME=/devops/oracle/<%= @environment_name %>/<%= @version_number.to_s %>)) and it ran through the syntax checker just fine. Also note you do not need the ".to_s"; the erb code does that automatically. Run the check without "| ruby -c" to see.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-05-04 20:33:53 -0500 )edit

I think the error "syntax error, unexpected tIVAR, expecting ')' ...nvironment_name @version_number ).to_s); _erbout.concat "\n"" MW_HOME=/devops/oracle/<%= @environment_name @version_number %> Both the variables are next to each other, there is no "/" in between. Thanks a lot for your time.

R gravatar imageR ( 2015-05-04 22:42:22 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-05-04 17:04:32 -0500

Seen: 1,131 times

Last updated: Sep 01 '15