For the regex to match, you'll need to backslash-escape (with a single backslash, since you're using single quotes) the dollar sign in your insertafter regex.
But even if you do that, it isn't going to work. There are several problems. First, each line that gets added will be added immediately after the `insertafter` line, so the order will end up being backwards. Second, there already is a "fi" line after "kill $pid" in DIPJobRunner.sh, so your "fi" won't be added. (Which is just as well, since they're in the wrong order anyway.
You can probably get what you want if you drop the with_items and change "line:" like this:
line: "sleep 3; if [ -f $PIDFILE ] ; then kill -9 $pid ; fi"