Ansible 使用fetch模块追加结果

Ansible 使用fetch模块追加结果,ansible,fetch,Ansible,Fetch,我试图在多台服务器上拉入一个同名文件,我只想将结果连接起来,但我认为fetch模块不允许我这样做。是否有人可以建议我使用另一个模块来完成此任务 当前非工作代码: - hosts: '{{ target }}' gather_facts: false tasks: - name: Pull in file.log contents from servers, concatenating results fetch: src: '/tmp/file.log

我试图在多台服务器上拉入一个同名文件,我只想将结果连接起来,但我认为fetch模块不允许我这样做。是否有人可以建议我使用另一个模块来完成此任务

当前非工作代码:

- hosts: '{{ target }}'
  gather_facts: false
  tasks:
    - name: Pull in file.log contents from servers, concatenating results
      fetch:
        src: '/tmp/file.log'
        dest: /tmp/fetched
        flat: yes
        fail_on_missing: no

例如,给定文件

shell>sshadmin@test_11cat/tmp/file.log
测试11
shell>sshadmin@test_12cat/tmp/file.log
测试12
shell>sshadmin@test_13cat/tmp/file.log
测试13
获取的文件的任务和时间戳,例如

-主机:测试11、测试12、测试13
任务:
-获取:
src:/tmp/file.log
dest:/tmp/fetched/file-{{time_stamp}}.log
平:是的
缺少上的失败:错误
节气门:1
变量:
时间戳:{{lookup('pipe',date+%Y-%m-%d{%H-%m-%S')}
给予

shell>树/tmp/fetched/
/tmp/fetched/
├── 文件-2021-03-22_21-16-54.log
├── 文件-2021-03-22_21-16-58.log
└── 文件-2021-03-22_21-17-02.log
然后是文件的内容,例如

-汇编:
src:/tmp/fetched
regexp:“^file-.*log$”
dest:/tmp/fetched/assemble-{{time_stamp}}.log
变量:
时间戳:{{lookup('pipe',date+%Y-%m-%d{%H-%m-%S')}
委托给:localhost
跑一次:对
给予

shell>cat/tmp/fetched/assembly-2021-03-22_21-17-07.log
测试11
测试12
测试13

如果要加快从多台主机(例如~100台)的传输速度,请增加并行任务的数量(例如
throttle:10
)。将主机名放入文件名中。否则,任务将覆盖具有相同时间戳的文件,例如

-获取:
src:/tmp/file.log
dest:/tmp/fetched/file-{{inventory\u hostname}}}-{{time\u stamp}}.log
平:是的
缺少上的失败:错误
节气门:3
变量:
时间戳:{{lookup('pipe',date+%Y-%m-%d{%H-%m-%S')}