scriptingpuppetfacter

failing to pass argument to puppet apply with facts


I am trying to pass a facter argument to puppet apply. Here's what I tried:

export FACTER_command="start"
puppet apply site.pp $FACTER_command

and in my code I have:

exec { 'some_exec':
  command => '/bin/bash -c "/some/path/to/scripts.sh -t some_arg $::command"',

...

I get this message error:

Error: '/bin/bash -c "/some/path/to/scripts.sh -t some_arg $::command"' returned 1 instead of one of [0]
Error: /Stage[main]/Standard/Exec[some_exec]/returns: change from 'notrun' to ['0'] failed: '/some/path/to/scripts.sh -t some_arg $::command"' returned 1 instead of one of [0]

Does anyone have any idea about this?

UPDATE

class standard{

        $param_test="/some/path/to/scripts.sh -t some_arg ${::command}"
        file{'kick_servers':
                ensure => 'file',
                path => '/some/path/to/scripts.sh',
                owner => 'some_user,
                group => 'some_user',
                mode => '0755',
                notify => Exec['some_exec']
        }

        exec { 'some_exec':
               command => '/bin/bash -c ${param_test}',
               cwd => "$home_user_dir",
               timeout     => 1800
        }
}

node default {
    include standard
}

And I get this error

Error: '/bin/bash -c $param_test' returned 2 instead of one of [0]
Error: /Stage[main]/Standard/Exec[some_exec]/returns: change from 'notrun' to ['0'] failed: '/bin/bash -c $param_test' returned 2 instead of one of [0]

Solution

  • Yes. You have at least two issues you need to fix there:

    1/

    The immediate cause of your problem is you have enclosed $::command inside single quotes, telling Puppet that you mean the literal string $::command, when you actually want the value of the fact there.

    2/

    You should not be passing $FACTER_command as an argument to puppet apply; you only need to export it as an environment variable (which you already did).

    So:

    Change puppet apply to:

    puppet apply site.pp 
    

    Change your exec to:

    exec { 'some_exec':
      command => "/bin/bash -c '/some/path/to/scripts.sh -t some_arg ${::command}'",
      ...
    }