【发布时间】:2019-04-04 18:56:52
【问题描述】:
我需要将文件从非库存远程机器 scp 到 ansible 中的库存远程机器。 scp 还需要密码才能访问。有没有一种简单的方法可以做到这一点?
例如: 我的库存
hosts:
- node1
- node2
文件所在的机器:
- gw_machine
在 node1 上,我想:
scp user@gw_machine:/path/ .
我知道复制、获取和同步模块,但它们似乎不适合我。我尝试编写一个期望脚本,但是当我第一次连接时它被挂起,因为 gw_machine 不在 node1 的 known_hosts 中。
我期待的任务:
- name: Scp file
shell: |
set timeout -1
spawn /usr/bin/scp user@gw_machine:/path_to_file/ .
expect "password:"
send "{{gw_passwd}}\n"
expect EOF
exit 0
args:
chdir: /tmp/
executable: /usr/bin/expect
当 gw_machine 在 node1 的已知主机中时,上述方法有效,但当它不在时挂起。我的机器上没有 sshpass
【问题讨论】: