ansible批量拉取远端文件

需求:
批量执行主机安全脚本,并取回脚本日志,日志格式以result_$IP.log结尾

一、分发脚本
more /opt/shell/yaml/py.yaml

  • hosts: "{{ host }}"
    tasks:

    • name: copy security.yaml
      copy: src=/mnt/script dest=/tmp
    • name: copy file
      copy: src=/mnt/script/fetch.sh dest=/tmp/data/
    • name: install security.py
      shell: /bin/bash /tmp/script/security.sh
      src=/mnt/script/fetch.sh 只为客户机创建目录/tmp/data/

    二、取回日志
    more /opt/shell/yaml/fetch.yaml

  • hosts: "{{ host }}"
    tasks:
    • name: copy result file
      fetch: src=/tmp/data/result_{{ inventory_hostname }}.log dest=/mnt/script/data
      //fetch 拉取远端主机参数模块;对比copy
      //src 是远程服务器的路径,dest 是本地路径
      // inventory_hostname 是ansible-playbook执行的主机
      // .log 是以什么log结尾的文件
      拉取客户端/tmp/data/result_以.log结尾的文件

猜你喜欢

转载自blog.51cto.com/11676712/2505779
今日推荐