Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5806

exec on Windows - command string interpreted differently than in cmd

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: PUP 4.3.2
    • Fix Version/s: None
    • Component/s: Types and Providers
    • Labels:
      None
    • Template:

      Description

      In Windows Command Prompt, on a box with cygwin I can do the following to sleep a while and ignore the return code:

      sleep 5 || true

      However the following manifest appears to be the same command, but does not work:

      class sleep {
        case $::osfamily {
          'windows': { exec { 'sleep':
                              command => 'sleep 5 || true',
                              path    => 'C:\cygwin64\bin',} }
          default:   { exec { 'sleep': command => '/usr/bin/sleep 500 || /bin/true', } }
        }
      }

      This results in the error:

      Info: Applying configuration version '1454501157'
      Notice: /Stage[main]/Sleep/Exec[sleep]/returns: sleep: invalid time interval `||'
      Notice: /Stage[main]/Sleep/Exec[sleep]/returns: sleep: invalid time interval `true'
      Notice: /Stage[main]/Sleep/Exec[sleep]/returns: Try `sleep --help' for more information.
      Error: sleep 5 || true returned 1 instead of one of [0]
      Error: /Stage[main]/Sleep/Exec[sleep]/returns: change from notrun to 0 failed: sleep 5 || true returned 1 instead of one of [0]

      It looks like all the terms in the command are being sent to sleep as arguments. In cmd, I can disambiguate by using parentheses:

      (sleep 5) || true

      but Puppet does not like this either:

      Info: Using configured environment 'sleep'
      Info: Retrieving pluginfacts
      Info: Retrieving plugin
      Info: Caching catalog for tbfn5ij5y0gi8v8.delivery.puppetlabs.net
      Info: Applying configuration version '1454501279'
      Error: Could not find command '(sleep'
      Error: /Stage[main]/Sleep/Exec[sleep]/returns: change from notrun to 0 failed: Could not find command '(sleep'

      Workaround:
      Use the "unless" property for the exec resource instead of trying to put boolean logic into the command property:

      class sleep {
        case $::osfamily {
          'windows': { exec { 'sleep':
                              command => 'true',
                              unless  => 'sleep 500',
                              path    => 'C:\cygwin64\bin',} }
          default:   { exec { 'sleep': command => '/usr/bin/sleep 500 || /bin/true', } }
        }
      }

        Attachments

          Activity

            jsd-sla-details-panel

              People

              • Assignee:
                james.stocks James Stocks
                Reporter:
                james.stocks James Stocks
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: