Puppet in a bash script

564 views
Skip to first unread message

Harish Agarwal

unread,
Nov 11, 2011, 1:40:31 PM11/11/11
to puppet...@googlegroups.com
Hello,

I'm using puppet via a bash script when I spin up a machine to configure it.  I'd like to restart the instance after puppet's run is complete.  In my bash script I have:

puppet agent --test
shutdown -r now


Puppet runs to completion, but "shutdown -r now" never executes.  I'm not sure why not - these are the last two lines in my bash script and everything else executes successfully.  Any help would be greatly appreciated.

-Harish

Rune Stensø

unread,
Nov 14, 2011, 3:42:15 AM11/14/11
to Puppet Users
I'm not sure where you execute this, but this sound like a problem
with your path.
For initialization script and such, where you're unsure of the path, I
suggest using the complete path for the command.
For example /usr/bin/puppet and /sbin/shutdown.

RuneSt.

John Kennedy

unread,
Nov 14, 2011, 7:01:18 AM11/14/11
to puppet...@googlegroups.com
Can you get the exit code of the puppet run and then, based on success or failure, do the reboot?

puppet agent --test
ANSW=$?
if [[ ${ANSW} -eq 0 ]]
then
echo "Puppet successful - Exit code ${ANSW}"
/sbin/shutdown -r now
else
echo "No puppet run - Exit code ${ANSW}
fi

This may tell you if puppet is cancelling the shutdown...

Harish Agarwal

unread,
Nov 19, 2011, 11:25:18 AM11/19/11
to puppet...@googlegroups.com
I did the echo above and didn't get any output....  It's as if this command is never encountered.  If there are errors thrown during the puppet run, will it throw an error and prevent the next command from executing?

BTW, I do have the full path of the binaries in my shell script now.

Mohamed Lrhazi

unread,
Nov 19, 2011, 7:27:39 PM11/19/11
to puppet...@googlegroups.com
Try adding -x to the bash (first line) to output each command as they are run...

What if you removed everything in the script but the shutdown
command.. does it work?


Mohamed.

> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/puppet-users/-/YQwIsn2GjGgJ.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>

Stefan Schulte

unread,
Nov 20, 2011, 10:15:50 AM11/20/11
to puppet...@googlegroups.com
On Sat, Nov 19, 2011 at 08:25:18AM -0800, Harish Agarwal wrote:
> I did the echo above and didn't get any output.... It's as if this command
> is never encountered. If there are errors thrown during the puppet run,
> will it throw an error and prevent the next command from executing?

If the shell is configured that way: Yes. Try to write the output of »set -o«
somewhere and look if »errexit« is set. If that is the case bash will
leave the script as soon as a command returns a non-true value.

>
> BTW, I do have the full path of the binaries in my shell script now.
>

Felix Frank

unread,
Dec 6, 2011, 10:05:18 AM12/6/11
to puppet...@googlegroups.com
Caution: puppet agent --test will return non-zero exit code if any
resources needed changing.

If in doubt, prefer puppet agent --one-time --no-daemonize (typos
notwithstanding).

On 11/14/2011 01:01 PM, John Kennedy wrote:
> puppet agent --test
> ANSW=$?

Otherwise, I'm stumped, this shouldn't happen. You could try and execute
puppet in a subshell and see if the rest of the script is run then.

( puppet agent --test )

Cheers,
Felix

Reply all
Reply to author
Forward
0 new messages