ansible通过通配符批量fetch或copy日志文件

1. ansible通过通配符从多个远端服务器fetch日志文件

[root@localhost data]# cat ../playbook/fetch.yml --- - hosts: all tasks: - name: find_file find: paths: /root/netqps/files/ # 远端服务器日志目录 patterns: "*.lzo" # 匹配以.lzo结尾的日志文件 recurse: no register: file_name - name: copy_file fetch: src: "{{ item.path }}" dest: /home/hjj/netqps/data/ # 本地ansible机器存放日志的目录 flat: yes with_items: "{{ file_name.files }}"

 https://www.toptechskills.com/ansible-tutorials-courses/ansible-fetch-module-tutorial-examples/

2. ansible通过通配符从ansible机器批量copy日志到远程机器

[root@localhost data]# cat playbook/copy.yml 
---
- hosts: all
  vars:
    filename: /home/hjj/netqps/data/*.lzo
  tasks:
  - copy:
      src: "{{ item }}"
      dest: /data06/dgy/
    with_fileglob:
      - "{{ filename }}"

 

posted @ 2022-02-23 10:10  明天OoO你好  阅读(2270)  评论(1编辑  收藏  举报