git-p4在通过ansible执行时无法克隆repo

时间:2016-04-19 13:02:38

标签: ansible rhel7 git-p4

我正在运行一个带有shell脚本的Ansible主机,它将我的repo克隆到我的本地git服务器。我从Perforce克隆,因此使用git-p4模块。

#!/bin/bash

p4port=myport
p4user=myuser
p4repourl=myurl
p4path=/usr/local/bin/p4
p4passwd=mypass
clone_dest=/root/mycode
gitp4=/usr/local/bin/git-p4

export P4PORT=$p4port
export P4USER=$p4user
$p4path trust -y
echo $p4passwd|$p4path login
echo "now using git-p4 to clone repo.."
python $gitp4 clone -v $p4repourl $clone_dest

我的目标机器有RHEL 7,如果我在目标机器上执行这个shell脚本,它可以正常工作。但是,如果我使用命令模块从我的Ansible主机运行它,则会抛出以下错误:

 ['git', 'config', 'git-p4.client']\nOpening pipe: ['p4', '-G', 'files', 'mydepot/...#head']\nTraceback (most recent call last):\n  File \"/usr/local/bin/git-p4\", line 3657, in <module>\n    main()\n  File \"/usr/local/bin/git-p4\", line 3651, in main\n    if not cmd.run(args):\n  File \"/usr/local/bin/git-p4\", line 3525, in run\n    if not P4Sync.run(self, depotPaths):\n  File \"/usr/local/bin/git-p4\", line 3330, in run\n    self.importHeadRevision(revision)\n  File \"/usr/local/bin/git-p4\", line 3079, in importHeadRevision\n    for info in p4CmdList([\"files\"] + fileArgs):\n  File \"/usr/local/bin/git-p4\", line 495, in p4CmdList\n    stdout=subprocess.PIPE)\n  File \"/usr/lib64/python2.7/subprocess.py\", line 711, in __init__\n    errread, errwrite)\n  File \"/usr/lib64/python2.7/subprocess.py\", line 1308, in _execute_child\n    raise child_exception\nOSError: [Errno 2] No such file or directory", "stdout": 

1 个答案:

答案 0 :(得分:0)

在ansible下你的PATH设置不正确,所以git-p4找不到p4。

另外,我建议您使用错误消息中的换行符替换\ n,以便更容易理解。