从 Ansible 中的托管节点获取大文件

问题描述 投票:0回答:1

我遇到了 Ansible

fetch
模块的限制。尝试获取一个稍大的文件 - 1MB 到 250MB 之间 - 这对于
fetch
来说太大了。

- name: get result files back
  fetch:
    src: /tmp/file_generated_previous_step.tar.gz
    dest: file_generated_{{ inventory_hostname }}.tar.gz
    flat: yes

当文件较小时,此方法有效,但当文件约为 1-2MB 时,会出现相当长的错误。

我的解决方法是在控制器中的文件上使用

scp
,如下所示:

- name: get result files back
  shell: ' scp {{ inventory_hostname }}:/tmp/file_generated_previous_step.tar.gz file_generated_{{ inventory_hostname }}.tar.gz'
  delegate_to: localhost

当我使用没有主机密码的公钥身份验证,但没有任何错误处理时,这是有效的。

所以,我的问题是:是否有正确的方法可以达到相同的结果?
限制条件是我使用的是 Ansible 2.4。

ansible fetch
1个回答
1
投票

尝试使用同步。它使用 rsync 并且可以毫无问题地处理大文件。

大多数人错过了它可以处理两个方向,包括从服务器到控制器:

mode:

Specify the direction of the synchronization.

In push mode the localhost or delegate is the source.

In pull mode the remote host in context is the source.

Choices:

    "pull"

    "push" ← (default)
© www.soinside.com 2019 - 2024. All rights reserved.