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

使用 delegate_to 在 ssh 内部执行时,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 }}"

这是挂起之前的输出:

<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'

知道可能出了什么问题吗?

答案1

经过一番调查,问题原来与代理转发有关。添加-o ForwardAgent = yes设置ssh_args即可/etc/ansible/ansible.cfg解决问题。

相关内容