zoukankan      html  css  js  c++  java
  • ansible 复制文件到本地 localhost

    fetch

    从远端获取文件,将这些文件按照树型方式按主机名分类进行存储。

    Parameters

    Parameter Choices/Defaults Comments
    dest - / required 存储目标的目录。如果 dest 是 /backup , src 在host.exmaple.com的位置是 /etc/profile, 那么最终的存储路径是/backup/host.example.com/etc/profile,主机名的依据是 inventory name
    fail_on_missing boolean Choices:noyes 如果设置成yes,在读取不到远端文件时会报错。
    flat boolean Choices:noyes 是否改变默认的将 hostname/path/to/file 追加到 dest 目录后。默认是no,即不允许改变这种默认的的文件组织方式,为的是如果有多个主机,dest为同一个文件会被覆盖。如果是yes,假如 dest/结尾,则文件保存在dest目录中;假如dest是文件,则直接保存为dest文件。
    src - / required 只能是文件,不能是目录(2.9),后面可能会支持目录。
    validate_checksum boolean Choices:noyes 获取文件后是否比较文件是否一致。

    Exmaple

    - name: Store file into /tmp/fetched/host.example.com/tmp/somefile
      fetch:
        src: /tmp/somefile
        dest: /tmp/fetched
    
    - name: Specifying a path directly
      fetch:
        src: /tmp/somefile
        dest: /tmp/prefix-{{ inventory_hostname }}
        flat: yes
    
    - name: Specifying a destination path
      fetch:
        src: /tmp/uniquefile
        dest: /tmp/special/
        flat: yes
    
    - name: Storing in a path relative to the playbook
      fetch:
        src: /tmp/uniquefile
        dest: special/prefix-{{ inventory_hostname }}
        flat: yes
    

    slurp

    从远端获取文件内容,并可以注册为变量(base64格式)

    Examples

    - name: Find out what the remote machine's mounts are
      slurp:
        src: /proc/mounts
      register: mounts
    
    - debug:
        msg: "{{ mounts['content'] | b64decode }}"
    
    # From the commandline, find the pid of the remote machine's sshd
    # $ ansible host -m slurp -a 'src=/var/run/sshd.pid'
    # host | SUCCESS => {
    #     "changed": false,
    #     "content": "MjE3OQo=",
    #     "encoding": "base64",
    #     "source": "/var/run/sshd.pid"
    # }
    # $ echo MjE3OQo= | base64 -d
    # 2179
    
  • 相关阅读:
    约瑟夫解决问题的循环链表
    [Erlang危机](5.1.0)VM检测概述
    找呀志_java网络编程(5)TCP和udp差额
    有序输出两棵二叉查找树中的元素
    1234567选择3个数字组合
    八皇后问题
    矩阵乘法运算
    求π的近似值
    证明不小于6的偶数都是两个素数之和
    最大公约数最小公倍数
  • 原文地址:https://www.cnblogs.com/hiyang/p/13748777.html
Copyright © 2011-2022 走看看