getAnsibleHostsFile() public static method

{ansible_hosts.dir}/project_{projectId}
public static getAnsibleHostsFile ( integer $projectId ) : string
$projectId integer 可以传入指定的id
return string
Example #1
0
 /**
  * @param Project $project
  * @return bool
  * @throws \Exception
  */
 protected function _saveAnsibleHosts(Project $project)
 {
     if (!$project->ansible) {
         // 未开启ansible, 不用保存
         return true;
     }
     $filePath = Project::getAnsibleHostsFile($project->id);
     $ret = @file_put_contents($filePath, $project->hosts);
     if (!$ret) {
         throw new \Exception(yii::t('conf', 'ansible hosts save error', ['path' => $filePath]));
     }
     return true;
 }
Example #2
0
 /**
  * 通过 ansible 复制文件模块, 并发传输文件
  *
  * @param string $src 宿主机文件路径
  * @param string $dest 目标机文件路径
  * @param array $hosts 可选的主机列表
  * @return bool|int
  */
 public function copyFilesByAnsibleCopy($src, $dest, $hosts = [])
 {
     $ansibleHosts = $this->_getAnsibleHosts($hosts);
     $localCommand = sprintf('%s ansible %s -u %s -m copy -a %s -i %s -f %d -T %d', $this->ansibleSshArgs, escapeshellarg($ansibleHosts), escapeshellarg($this->getConfig()->release_user), escapeshellarg('src=' . $src . ' dest=' . $dest), escapeshellarg(Project::getAnsibleHostsFile()), $this->ansibleFork, $this->ansibleTimeout);
     return $this->runLocalCommand($localCommand);
 }