首页 > 其他 > 详细

ansible批量拉取远端文件

时间:2020-06-18 22:20:10      阅读:251      评论:0      收藏:0      [点我收藏+]
需求:
批量执行主机安全脚本,并取回脚本日志,日志格式以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结尾的文件

ansible批量拉取远端文件

原文:https://blog.51cto.com/11676712/2505779

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!