Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function run($callback = null)
 {
     $event = new Event\AnsibleEvent($this->ansible, $this, $this->command);
     $dispatcher = $this->ansible->getDispatcher();
     try {
         // Throw the "ansible.command.prepare" event prior to executing.
         $dispatcher->dispatch(Event\AnsibleEvents::GIT_PREPARE, $event);
         // Execute command if it is not flagged to be bypassed and throw the
         // "ansible.command.success" event, otherwise do not execute the comamnd
         // and throw the "ansible.command.bypass" event.
         if ($this->command->notBypassed()) {
             parent::run($callback);
             if ($this->isSuccessful()) {
                 $dispatcher->dispatch(Event\AnsibleEvents::GIT_SUCCESS, $event);
             } else {
                 $output = $this->getErrorOutput();
                 if (trim($output) == '') {
                     $output = $this->getOutput();
                 }
                 throw new \RuntimeException($output);
             }
         } else {
             $dispatcher->dispatch(Event\AnsibleEvents::GIT_BYPASS, $event);
         }
     } catch (\RuntimeException $e) {
         $dispatcher->dispatch(Event\AnsibleEvents::GIT_ERROR, $event);
         throw new AnsibleException($e->getMessage());
     }
 }
Пример #2
0
 /**
  * Runs a Ansible command.
  *
  * @param \AnsibleWrapper\AnsibleCommand $command
  *   The Ansible command being executed.
  * @param string|null $cwd
  *   Explicitly specify the working directory of the Ansible process. Defaults
  *   to null which automatically sets the working directory based on the
  *   command being executed relative to the working copy.
  *
  * @return string
  *   The STDOUT returned by the Ansible command.
  *
  * @throws \AnsibleWrapper\AnsibleException
  *
  * @see Process
  */
 public function run(AnsibleCommand $command, $cwd = null)
 {
     $wrapper = $this;
     $process = new AnsibleProcess($this, $command, $cwd);
     $process->run(function ($type, $buffer) use($wrapper, $process, $command) {
         $event = new Event\AnsibleOutputEvent($wrapper, $process, $command, $type, $buffer);
         $wrapper->getDispatcher()->dispatch(Event\AnsibleEvents::GIT_OUTPUT, $event);
     });
     return $command->notBypassed() ? $process->getOutput() : '';
 }