Ask Your Question

Running .sh script fails returned 1 instead of one of [0]

asked 2014-10-01 16:30:42 -0500

GLN gravatar image


I have a deployment that has to run a script ( at the end so a service is added on start-up. When I run the command from the command line "./ install" it is working fine. When I try to run it from my class it is not working, it is failing with

"change from notrun to 0 failed: install returned 1 instead of one of [0]".

My exec looks like this:

    exec { 'add_to_startup':
        command     => ' install',
        cwd => "/opt/test/",
        path => "/opt/test/",           

I tried to add

        user => root,

        provider => shell,

I verified that has #!/bin/sh at the beginning.

and I still get the same error. I must be missing something small, but I can't find out why this is not running. What am I doing wrong?

Thanks in advance. GLN

edit retag flag offensive close merge delete


try adding logoutput => on_failure, to your exec and run again. Edit your question to add any additional information.

ramindk gravatar imageramindk ( 2014-10-01 17:34:09 -0500 )edit

thanks for the advice, I will do that and post the output.

GLN gravatar imageGLN ( 2014-10-01 18:52:39 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2014-10-02 03:01:54 -0500

jonn gravatar image

Hi - if you run the script on the command line, what is the return code? You can get the return code like this:

# /opt/test/ install
# echo $?

If it does return 1, then you can either modify the script so that it returns 0 on success, or use the returns attribute on the exec type to tell Puppet which return codes should be treated as successful.

edit flag offensive delete link more

answered 2014-10-02 09:26:39 -0500

GLN gravatar image

updated 2014-10-02 09:49:18 -0500

I found the source of the problem and kicking myself in the ... I can see the following errors line 38: which: command not found

and then

[] Error: this script should only be run as root does have whoami='which whoami' in line 38 and then the shell script checks if whoami==root and if the user is not root it exits. so it looks like the 'which whoami' failure is causing me the problems.

When I run 'which whoami' manually I get /usr/bin/whoami , when I run manually it works fine but for when puppet is running I get command not found for 'which' and then I noticed some posting about not having environment on exec.

The solution ended up adding path

path => ":/usr/bin:/bin:/usr/sbin:/sbin",

Thanks everybody for your time and help.


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-10-01 16:30:42 -0500

Seen: 2,370 times

Last updated: Oct 02 '14