zoukankan      html  css  js  c++  java
  • Ansible在节点间传输文件

    1. 在控制节点(the control machine )与远程节点( the current remote host)之间传输文件

     

     

    1.1 如果需要传输文件,可以使用copy模块,注意copy模块不能递归目录

     

      copy: src=/path/on/control_machine/{{ item }} dest=/path/on/reomte_host remote_src=yes
      with_items:
        - "file_1"
        - "file_2"
    

    1.2 可以使用unarchive模块传输打包好的文件夹,在远程节点上自动解压:

    - name: copy your folder from control machine to remote host
      unarchive: src=/path/on/control_machine/{{ item }} dest=/path/on/reomte_host
      with_items:
        - "file_1"
        - "file_2"

     

    1.3 使用synchronize模块,设置mode=pull,即远程节点从控制机器拉取数据:

     

    - name: copy file from control machine to remote host
      synchronize: mode=pull src=/path/on/control_machine/{{ item }} dest=/path/on/reomte_host
      with_items:
        - "file_1"
        - "file_2"
    

    2.当需要在两个远程主机(remote host )上面互相传输数据时候:

    2.1 当远程节点为ServerB的时候,将ServerA的文件夹传输到ServerB上:

    - hosts: ServerB
      tasks:
        - name: Transfer file from ServerA to ServerB
          synchronize:
            src: /path/on/server_a
            dest: /path/on/server_b
          delegate_to: ServerA

     

    2.2 当远程节点为ServerA的时候,将ServerA的文件夹传输到ServerB上:

     

    - hosts: ServerA
      tasks:
        - name: Transfer file from ServerA to ServerB
          synchronize:
            src: /path/on/server_a
            dest: /path/on/server_b
            mode: pull
          delegate_to: ServerB

     

    2.3 或者使用SCP命令:

     

    - name: Transfer file from ServerB to ServerA
      shell: scp  -r /path/on/server_b node@ServerA:/path/on/server_a
      ignore_errors: True
      delegate_to: ServerB
    

     

     

     

    REF: http://stackoverflow.com/questions/25505146/how-to-copy-files-between-two-nodes-using-ansible

            http://stackoverflow.com/questions/25576871/ansible-best-practice-to-copy-directories

  • 相关阅读:
    scp命令(基于ssh上传文件等)
    mac上安装ruby
    Access denied for user ''@'localhost' to database 'mysql'
    3.ruby语法基础,全部变量,实例变量,类变量,局部变量的使用和注意的要点
    2.ruby基本语法,类的定义
    1.ruby基本格式
    neo4j在linux下的安装
    mongodb导入json文件
    mongodb 安装启动
    Junit4
  • 原文地址:https://www.cnblogs.com/xiaoxiaoleo/p/6626299.html
Copyright © 2011-2022 走看看