Puppet [SOLVED]: Puppet sed and replace

Puppet [SOLVED]: Puppet sed and replace

Home Forums Automation Tools Puppet Puppet [SOLVED]: Puppet sed and replace

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #221605

    Cloudy Point


    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
    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.


    Cloudy Point

    Accepted AnswerAnswer

    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.

    Source: https://stackoverflow.com/questions/47172674/puppet-sed-and-replace
    Author: oliv
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.