使用 delegate_to 在 ssh 内执行时 Ansible 同步挂起

Már*_*ins 5 ssh rsync ansible

当直接从我的机器运行时,以下任务工作正常。当我通过 SSH 从远程计算机运行它时,它永远挂起。

这是任务:

  - name: deploy public directory
    synchronize: src="{{ my_root_path }}/.deploy/office/public/" dest="{{ my_root_path}}/office/public/" compress=no checksum=yes delete=yes recursive=yes times=yes links=yes archive=no rsync_opts=--no-motd,--exclude=.gitignore
    delegate_to: "{{ inventory_hostname }}"
Run Code Online (Sandbox Code Playgroud)

这是挂起之前的输出:

<88.81.184.149> ESTABLISH CONNECTION FOR USER: root
<88.81.184.149> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 88.81.184.149 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440505364.9-19277754718304 && echo $HOME/.ansible/tmp/ansible-tmp-1440505364.9-19277754718304'
<88.81.184.149> PUT /tmp/tmpr44yYm TO /root/.ansible/tmp/ansible-tmp-1440505364.9-19277754718304/synchronize
<88.81.184.149> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 88.81.184.149 /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1440505364.9-19277754718304/synchronize; rm -rf /root/.ansible/tmp/ansible-tmp-1440505364.9-19277754718304/ >/dev/null 2>&1'
Run Code Online (Sandbox Code Playgroud)

关于可能出什么问题的任何想法吗?

Már*_*ins 4

经过一番排查,问题出在代理转发上。添加-o ForwardAgent = yesssh_args设置中就/etc/ansible/ansible.cfg达到了目的。

  • 非常感谢,我用你的解决方案解决了问题。[ssh_connection]\nssh_args= -o ForwardAgent=yes (3认同)