Im learning Puppet and currently trying to install tomcat. While trying to replace the Catalina home on the startup.sh using sed in the exec block, Im facing the below error.
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at '|export CATALINA_HOME=' at /etc/puppetlabs/code/environments/production/modules/tomcat/manifests/init.pp:26:58 on node agent
Current value of startup.sh
export CATALINA_HOME="/home/john"
export JAVA_HOME="/usr"
......
.....
Expected output
export CATALINA_HOME="/home/john/apache-tomcat-6.0.44"
export JAVA_HOME="/usr/java/default"
My code snippet
.......
exec { 'modify_file':
command => "sed -i 's|export CATALINA_HOME="/home/john"|export CATALINA_HOME="/home/john/apache-tomcat-6.0.44"|g' /home/john/apache-tomcat-6.0.44/bin/startup.sh"
path => '/bin',
}
Any help is really appreciated, thanks in advance.
Also, I had went thru the puppet documents regarding path atrribute of exec block but I'm not sure why it is being used and what should be my path value in my manifest file.
Your sed
expression is likely broken due to quote mismatch.
You could simplify the sed
command by using:
sed -i '/CATALINA_HOME=/s,/home/john,&/apache-tomcat-6.0.44,;/JAVA_HOME=/s,/usr,&/java/default,' /home/john/apache-tomcat-6.0.44/bin/startup.sh
The expression contains 2 commands for both CATALINA_HOME
and JAVA_HOME
. Both commands uses the same syntax to append the required string to the variable declaration.
/<regex>/s
will perform the subsitution on line with the <regex>
.
The ,
is the command separator. I usually use /
unless the pattern to search is a directory path.
&
is printing the pattern space, i.e. the matched pattern.