需求:
批量执行主机平安剧本,并取回剧本日志,日志花样以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末端的文件