我正在尝试在本地运行此任务(在运行playbook的机器上):
- name: get the local repo's branch name
local_action: git branch | awk '/^\*/{print $2}'
register: branchName
我尝试了很多变化但都没有成功
所有其他任务都应该在目标主机上运行,这就是为什么不能在本地运行整个playbook的原因
TASK: [get the local repo's branch name] **************************************
<127.0.0.1> REMOTE_MODULE git branch | awk '/^\*/{print $2}'
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172 && echo $HOME/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172']
<127.0.0.1> PUT /tmp/tmpQVocvw TO /home/max/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172/git
<127.0.0.1> EXEC ['/bin/sh', '-c', '/usr/bin/python /home/max/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172/git; rm -rf /home/max/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172/ >/dev/null 2>&1']
failed: [portal-dev] => {"failed": true}
msg: this module requires key=value arguments (['branch', '|', 'awk', '/^\\*/{print $2}'])
FATAL: all hosts have already failed -- aborting
更新:
我按照下面 bkan 的建议走了一步,但是还没有完全解决。
- name: get the local repo's branch name
local_action: command git branch | (awk '/^\*/{print $2}')
sudo: no
register: branchName
现在git命令被启动了,但是并不正确(请参见下面的错误信息)。
请注意,此命令作为"shell"可以完美运行,但不幸的是没有local_action的本地_shell等效命令...
failed: [portal-dev] => {"changed": true, "cmd": ["git", "branch", "|", "(awk", "/^\\*/{print $2})"], "delta": "0:00:00.002980", "end": "2014-08-05 18:00:01.293632", "rc": 129, "start": "2014-08-05 18:00:01.290652"}
stderr: usage: git branch [options] [-r | -a] [--merged | --no-merged]
or: git branch [options] [-l] [-f] <branchname> [<start-point>]
or: git branch [options] [-r] (-d | -D) <branchname>...
or: git branch [options] (-m | -M) [<oldbranch>] <newbranch>
...
local_action: shell
吗? - seanflocal_action: shell
解决了我的问题,但事实证明这是一个委派错误:https://github.com/ansible/ansible/issues/10906 - seanfshell
没有起作用,但command
起了作用。我正在运行 Ansible 版本 2.0.1.0。我的 Playbook 行现在是local_action: command ssh root@blog exit
(ssh 进入主机然后立即退出)。 - Keith Bennett