[TriLUG] init script behaves different when invoked from Ansible playbook??

Phillip Rhodes (Fogbeam Labs) via TriLUG trilug at trilug.org
Thu May 11 13:25:27 EDT 2017


FWIW, I took the whole dirname business out and temporarily hardcoded the
value of the SCRIPTPATH variable and it gets past that point in the script
now.  It ultimately fails somewhere else for a different reason, but it
looks like the dirname thing was killing the script.

I'm not even sure how that's possible though.  First of all, dirname is a
pretty innocuous command from what I can tell, and - more to the point - I
thought that if something in a subshell returned an error code,it would be
return to the parent, which would *not* automatically die.   Hence, you
should be able to do something like

echo "? = $?" after the subshell and get the exit code.  But I added that
and that echo line never executed.  So apparently, somehow, the attempt to
invoke dirname in a subshell was causing the parent script to abort.

Which is even more confusing given that it works when you run it locally. I
even tried plugging in the absolute path to dirname (/bin/dirname) thinking
it might be something path related, but still no joy.

This whole thing has me befuddled, but then again, I'm not a shell
scripting expert to begin with.  :-)


Phil


On Thu, May 11, 2017 at 1:20 PM, Brian Gerard <bgerard at gmail.com> wrote:

> I don't know that it will get you out of your current predicament, but a
> safer
> way to get the path would be a combination of 'readlink' and 'dirname',
> thus:
> SCRIPTPATH=$(dirname $(readlink -m $0))
>
> Brian
>
> On 05/11/2017 01:06 PM, Phillip Rhodes (Fogbeam Labs) wrote:
> >
> >
> > On Thu, May 11, 2017 at 1:01 PM, Brian Gerard via TriLUG <
> trilug at trilug.org
> > <mailto:trilug at trilug.org>> wrote:
> >
> >     When you say it dies in the middle, is there a particular point at
> which
> >     it dies every time?  Ie - you added a bunch of debugging echoes in
> there;
> >     can you say what it's trying to do when it dies?  If not, I'd
> recommend
> >     adding more and appending to a log in /tmp or something to see if
> you can
> >     pinpoint where it's failing.
> >
> >
> > Yes, it always fails dies (or hangs, I just realized it might still be
> running)
> > at the same place.  It's trying to do this business:
> >
> > SCRIPTPATH=$(dirname "$0")
> >
> >
> >
> >
> >
> >     FWIW, the first thing that popped into my brain was the possibility
> that
> >     Ansible might have mucked about with the shell syntax, if you're
> handling
> >     that script as a "template" rather than a "file", but since it seems
> to
> >     work from outside of Ansible, I'm less sure of that.  It might be
> worth
> >     looking at anyway, just to check.  Diffing the source script and the
> installed
> >     version, iow.
> >
> >
> > Oh yeah, that's a good thought.  I was thinking in terms of "I'm not
> explicitly
> > doing any
> > substitution stuff in here" and was treating the template as equivalent
> to a
> > static file.  That
> > is probably a bad idea, even if it isn't directly the cause of my
> problem here.
> >
> >
> > I'm trying it again now with the script spitting out $BASHPID at the
> beginning
> > to (hopefully) I can determine if maybe it's hung, as opposed to the
> process
> > having aborted.
> >
> >
> > Phil
> >
>
>


More information about the TriLUG mailing list