Search code examples
linuxpuppetpuppet-enterprise

Puppet Could not find command 'cd'


Hi there this part of my code causes an error.

   path    => '/bin:/sbin/:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
   cwd     => "/var/rapid7installer && unzip ${install_file}",
   creates => '/var/rapid7installer/agent_installer.sh',
   timeout => $timeout,
   require => [
     Package['unzip'],
     File["/var/rapid7installer/${install_file}"],
   ],
 }->

This is the error I am getting.

Error: /Stage[main]/Profiles::Rapid7agent/Exec[Rapid7 Agent Installation Unzip]/returns: change from 'notrun' to ['0'] failed: Could not find command 'cd'

I am hoping someone can help me or point me in the right direction. Thank you for looking and your time.


Solution

  • The fragment presented in the question is an incomplete unit, but it appears to be part of the declaration of an Exec resource. In that case, the cwd attribute is surely incorrect:

      cwd     => "/var/rapid7installer && unzip ${install_file}",
    

    , and it probably is directly responsible for the issue you observe. The value of that attribute should be the name of a directory that should be the working directory during execution of the exec's command. From context, it appears that that should be just the first part, /var/rapid7installer. The actual command to execute must be conveyed via the command attribute, which defaults to the resource title if not given explicitly.

    Thus, it appears you want something more like this:

    exec { 'Rapid7 Agent Installation Unzip':
       command => "unzip ${install_file}",
       path    => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
       cwd     => '/var/rapid7installer',
       creates => '/var/rapid7installer/agent_installer.sh',
       timeout => $timeout,
       require => [
         Package['unzip'],
         File["/var/rapid7installer/${install_file}"],
       ],
    }