ansible批量拉取远端文件

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

1、分发脚本
more /opt/shell/yaml/py.yaml 安全

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

    • 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/

    2、取回日志
    more /opt/shell/yaml/fetch.yaml 服务器

  • hosts: "{{ host }}"
    tasks:
    • name: copy result filefetch: 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结尾的文件
相关文章
相关标签/搜索