在ansible中使用SCP在服务器之间复制文件?
Copy files between servers using SCP in ansible?
我已经在我的机器上执行了一个 ansible 脚本。所做的是
1.Copy 一个文件从我的机器到远程机器 docker 容器 运行
file.pb
2.Execute docker 容器上的命令。该命令使用复制的文件并对其进行签名。
这是命令
peer channel signconfigtx -f file.pb
现在我想在从现在所在的docker容器中用相同的ansible脚本签名后,再次将这个签名文件复制到另一台机器上。
我想尝试 SCP
但不确定它如何工作,因为它会要求输入密码。
任何人都可以建议我该怎么做吗?
编辑:
我尝试在我的本地计算机上从远程服务器获取文件,但出现以下错误
fatal: [user1]: FAILED! => {"msg": "Unable to create local
directories(/home/dhiraj/ansible_practise/playlist/fetched/user1/home/user1/Documents/Blockchain/network/scripts):
[Errno 20] Not a directory:
'/home/dhiraj/ansible_practise/playlist/fetched/user1'"}
下面是我的ansible脚本
- name: Fetching a file from remote server
fetch:
src: "/home/user1/Documents/Blockchain/network/scripts/file.pb"
dest: fetched
还有更多选择。
1) scp 从 docker 到另一台机器
- 将 运行ning scp at Docker 用户的 public 密钥放到另一台机器上连接的用户 authorized_key。
- 在 docker 运行 command: scp file.pb user@another_machine:file.pdb
2) 获取并复制
3) 获取并拉取
- fetch 从 docker 到您的机器
- 在另一台机器上 运行 ansible-pull 和 运行 将从您的机器获取文件的剧本。
4) 运行 在另一台机器上 scp ...
我没有直接在服务器之间复制文件,而是使用了 fetch
ansible 模块。在 fetch 中,我只需要定义 source path
和 destination path
。
这是示例
- name: Fetching a file from remote server
fetch:
src: "{{ DEST }}/Documents/Blockchain/network/scripts/file.pb"
dest: /home/fetched/
flat: yes // it will not create dir strcuture as same as source
validate_checksum: false
我已经在我的机器上执行了一个 ansible 脚本。所做的是
1.Copy 一个文件从我的机器到远程机器 docker 容器 运行
file.pb
2.Execute docker 容器上的命令。该命令使用复制的文件并对其进行签名。
这是命令
peer channel signconfigtx -f file.pb
现在我想在从现在所在的docker容器中用相同的ansible脚本签名后,再次将这个签名文件复制到另一台机器上。
我想尝试 SCP
但不确定它如何工作,因为它会要求输入密码。
任何人都可以建议我该怎么做吗?
编辑:
我尝试在我的本地计算机上从远程服务器获取文件,但出现以下错误
fatal: [user1]: FAILED! => {"msg": "Unable to create local directories(/home/dhiraj/ansible_practise/playlist/fetched/user1/home/user1/Documents/Blockchain/network/scripts): [Errno 20] Not a directory: '/home/dhiraj/ansible_practise/playlist/fetched/user1'"}
下面是我的ansible脚本
- name: Fetching a file from remote server
fetch:
src: "/home/user1/Documents/Blockchain/network/scripts/file.pb"
dest: fetched
还有更多选择。
1) scp 从 docker 到另一台机器
- 将 运行ning scp at Docker 用户的 public 密钥放到另一台机器上连接的用户 authorized_key。
- 在 docker 运行 command: scp file.pb user@another_machine:file.pdb
2) 获取并复制
3) 获取并拉取
- fetch 从 docker 到您的机器
- 在另一台机器上 运行 ansible-pull 和 运行 将从您的机器获取文件的剧本。
4) 运行 在另一台机器上 scp ...
我没有直接在服务器之间复制文件,而是使用了 fetch
ansible 模块。在 fetch 中,我只需要定义 source path
和 destination path
。
这是示例
- name: Fetching a file from remote server
fetch:
src: "{{ DEST }}/Documents/Blockchain/network/scripts/file.pb"
dest: /home/fetched/
flat: yes // it will not create dir strcuture as same as source
validate_checksum: false