【问题标题】:Ansible script to copy file from multiple servers从多个服务器复制文件的 Ansible 脚本
【发布时间】:2019-02-08 13:07:17
【问题描述】:

只是想了解您可以使用什么方法将目录从 5-10 个远程主机复制到目标(例如跳转服务器)?

我一直在研究的一个是:

---

 - hosts: all
   gather_facts: true

   vars:
     src_path: "/source_path/"
     dest_path: "/destination_path/{{ inventory_hostname }}/"

   tasks:
    - name: Copy a location from REMOTE server to the LOCAL jump box
      tags: sync-pull
      synchronize:
        # The synchronize module forces–delay-updates to avoid leaving a destination in a broken in-between state if the underlying rsync process encounters an error.
        src: "{{ src_path }}"
        dest: "{{ dest_path }}"
        mode: pull       # In pull mode the remote host in context is the source.
        delete: yes      # Delete files in dest that don't exist (after transfer, not before) in the src path. This option requires recursive=yes.
        recursive: yes
        compress: yes    # Default yes.  Compress file data during the transfer
        times: yes       # Preserve modification times
        rsync_timeout: 15 # Specify a --timeout for the rsync command in seconds.
        rsync_opts:
         - "--exclude=.git"
         - "--exclude=*.log"
         - "--exclude=*.log.gz"

还有许多事情仍在试图弄清楚。其中一些是:

1) 如何确保根据主机选择路径.. 即 Host1 有 3 个 source_path。我不确定这将如何完成!

2) 如果 source_path 没有所需的权限,则脚本失败并出现错误:

send_files 未能打开 \"source_path/iamlog.log\":权限被拒绝 (13)\ 无法弄清楚这里可以做什么!

【问题讨论】:

    标签: ansible


    【解决方案1】:

    首先要检查的是您尝试复制的文件的文件权限,由于运行 ansible-playbook 的用户没有读取该文件的权限,因此文件似乎没有复制。

    检查

    ls -lhtra iamlog.log

    最坏的情况是暂时给每个人全部权限,看看它是否有效:

    chmod 777 iamlog.log

    如果可行,您可能需要将 ansible-playbook 执行用户添加到服务器上的本地组中,以授予访问权限或以该文件的用户所有者身份运行。 HTH。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      相关资源
      最近更新 更多