1

I have the following resource declaration to set the setenv.sh file via augeas in puppet.

augeas {'test':
    lens    => 'Properties.lns',
    incl    => '/tmp/setenv.sh',
    changes => "set CATALINA_OPTS \" $CATALINA_OPTS -XX:PermSize=192m -XX:MaxPermSize=192m \"",
}

I have run into a few issues with the above.

  1. The file basically appends configs to the CATALINA_OPTS variable which means when I run augeas it removes all instances of that variable and replaces it with my change. How can I achieve the following?

    CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/appdynamics/appagent/javaagent.jar"
    CATALINA_OPTS="$CATALINA_OPTS -XX:PermSize=192m -XX:MaxPermSize=192m"
    
  2. An attempt to run the above fails due to the quotes. The debug output shows:

    Debug: Augeas[test](provider=augeas): sending command 'set' with params ["/files/tmp/setenv.sh/CATALINA_OPTS", "  -XX:PermSize=192m -XX:MaxPermSize=192m "]
    Debug: Augeas[test](provider=augeas): Put failed on one or more files, output from /augeas//error:
    Debug: Augeas[test](provider=augeas): /augeas/files/tmp/setenv.sh/error = put_failed
    Debug: Augeas[test](provider=augeas): /augeas/files/tmp/setenv.sh/error/path = /files/tmp/setenv.sh
    Debug: Augeas[test](provider=augeas): /augeas/files/tmp/setenv.sh/error/lens = /usr/share/augeas/lenses/dist/properties.aug:50.25-.100:
    Debug: Augeas[test](provider=augeas): /augeas/files/tmp/setenv.sh/error/message = Malformed child node 'CATALINA_OPTS'
    

How can I have the change use double quotes in the string?

0

If you just want to append lines to a file, try using file_line resource instead of augeas, for example:

file_line { 'line1':
  path => '/tmp/setenv.sh',
  line => 'CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/appdynamics/appagent/javaagent.jar"',
}

file_line { 'line2':
  path => '/tmp/setenv.sh',
  line => 'CATALINA_OPTS="$CATALINA_OPTS -XX:PermSize=192m -XX:MaxPermSize=192m"',
}

To avoid issues with doublequotes, just singlequote the whole file line. If you want to add line to a specific place in the file, you can use the 'after' property.

file_line is available in 'puppetlabs/stdlib' module.

  • Thanks. I also discovered that this needs to be added mid-file. I believe file_line appends to the end of the line correct? – kaizenCoder May 11 '15 at 2:50
  • My answers states: 'if you want to add line to a specific place in the file....'. So, try the 'after => ' param. – Jakov Sosic May 11 '15 at 2:53
1

If you want to impact on the last CATALINA_OPTS variable, you need to specify it:

augeas {'test':
    lens    => 'Properties.lns',
    incl    => '/tmp/setenv.sh',
    changes => "set CATALINA_OPTS[last()] \" $CATALINA_OPTS -XX:PermSize=192m -XX:MaxPermSize=192m \"",
}

You could use [2] instead of [last()], but at least the latter one ensures it's the last occurrence of the variable in the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.