个人技术分享

ansible-copy用法

概述

ansible copy 常用用法举例

不带目录拷贝,拷贝的地址要写全
带目录拷贝,拷贝路径不要写在 dest 路径中

实践

不带目录拷贝

# with_fileglob 是 Ansible 中的一个循环关键字,用于处理文件通配符匹配的结果
# 遍历 addons/files/*.txt文件
# dest: /data/soft/test 目录要事先存在,才能正常的copy
- name: Copy configuration files
  copy:
    src: "{{ item }}"
    dest: /data/soft/test
    owner: root
    group: root
    mode: 0644
  with_fileglob:
    - "*.txt"

在这里插入图片描述

带目录拷贝

#     src: "{{ inventory_dir }}/centos-common"
#    dest: "{{ inventory_dir }}/centos-common"
# 会形成 /root/k8s-ansible/centos-common/centos-common  多了一层 centos-common
- name: 1.分发
  copy:
    src: "{{ inventory_dir }}/centos-common"
    dest: "{{ inventory_dir }}"
    force: yes
    mode: 0755