我正在尝试使用 ansible 同步在两个遥控器之间复制文件。
我的剧本看起来像:
- hosts: newserver
tasks:
- name: Copy images from old to new
synchronize:
src: /var/www/production/
dest: /var/www/production/
delegate_to: oldserver
Run Code Online (Sandbox Code Playgroud)
和newserver
是oldserver
在我的库存文件中定义的。如果我替换oldserver
为完整主机名,则 delegate_to 可以工作。否则它会抱怨无法访问。oldserver
在其他剧本的其他地方工作得很好。
delegate_to 不使用库存吗?
我得到的错误是:
TASK [Copy images from old to new] *************************************************
fatal: [thr.cs.unc.edu]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ", "unreachable": true}
Run Code Online (Sandbox Code Playgroud)
newserver
可以从 到达oldserver
。正如我上面所说,如果我在 delegate_to 中更改oldserver
为它就可以了。gbserver3.cs.unc.edu
我的主机文件如下所示:
[newserver]
thr.cs.unc.edu
[oldserver]
gbserver3.cs.unc.edu
Run Code Online (Sandbox Code Playgroud)