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?

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
kaizenCoder
  • 343
  • 2
  • 8
  • 22

2 Answers2

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.

raphink
  • 11,987
  • 6
  • 37
  • 48
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.

Jakov Sosic
  • 5,267
  • 4
  • 24
  • 35
  • 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 02: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 02:53