Puppet [SOLVED]: failing to pass argument to puppet apply with facts

Puppet [SOLVED]: failing to pass argument to puppet apply with facts

Home Forums Automation Tools Puppet Puppet [SOLVED]: failing to pass argument to puppet apply with facts

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #241077

    Cloudy Point
    Keymaster

    QuestionQuestion

    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]
    

    #241078

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    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}'",
      ...
    }
    

    Source: https://stackoverflow.com/questions/47750582/failing-to-pass-argument-to-puppet-apply-with-facts
    Author: Alex Harvey
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.