Ansible同步始终预先添加username @ host

时间:2017-07-12 10:56:01

标签: ansible rsync

我在本地计算机(macOs)上运行ansible 2.3.1.0并试图实现:

  • 连接到user1@host1
  • 将文件从user2@host2:/path/to/file复制到user1@host1:/tmp/path/to/file

我在我的本地,host1hostsuser1remote_user

- synchronize: mode=pull src=user2@host2:/path/to/file dest=/tmp/path/to/file 

输出错误:

/usr/bin/rsync (...) user1@host1:user2@host2:/path/to/file /tmp/path/to/file 

结论

我一直在尝试不同的选择。我调试了ansible。我无法理解错误。

帮助!

编辑1

我还尝试添加delegate_to

- synchronize: mode=pull src=/path/to/file dest=/tmp/path/to/file 
  delegate_to: host2

它给出了:

fatal: [host1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password,keyboard-interactive).\r\n", "unreachable": true}

还有:

- synchronize: mode=pull src=/path/to/file dest=/tmp/path/to/file 
  delegate_to: user2@host2

给出了:

fatal: [host1 -> host2]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no --rsync-path=sudo rsync --out-format=<<CHANGED>>%i %n%L host1:/path/to/file /tmp/path/to/file", "failed": true, "msg": "Permission denied (publickey).\r\nrsync: connection unexpectedly closed (0 bytes received so far) [Receiver]\nrsync error: unexplained error (code 255) at io.c(235) [Receiver=3.1.2]\n", "rc": 255}

注意:ssh user1@host1然后ssh user2@host2使用ssh密钥(无需密码)

1 个答案:

答案 0 :(得分:0)

请注意modules' docs

中的这些说明
  

对于同步模块,“本地主机”是同步任务发起的主机,“目标主机”是主机同步连接。

     

可以使用delegate_to将“本地主机”更改为其他主机。这样可以在两台远程主机之间进行复制,也可以完全在一台远程计算机上进行复制

我想,您可能想尝试(假设Ansible可以连接到host2):

- synchronize:
    src: /path/to/file
    dest: /tmp/path/to/file
  delegate_to: host2
相关问题