ansible - 如何在ansible中使用fetch模块

标签 ansible

我想使用 ansible playbook 将文件从远程服务器复制到本地计算机。但是,当我使用 fetch module 执行此操作时,会在本地计算机上创建具有完整目录结构的服务器 IP 文件夹。有办法避免这种情况吗?以下是我的剧本中的任务

- name: Copy files from remote to local
  fetch:
    src: /etc/pki/ca.pem
    dest: /etc/workloadmgr

最佳答案

使用fetchflat选项:

Allows you to override the default behavior of appending hostname/path/to/file to the destination. If dest ends with '/', it will use the basename of the source file, similar to the copy module. This can be useful if working with a single host, or if retrieving files that are uniquely named per host. If using multiple hosts with the same filename, the file will be overwritten for each host.

像这样

- name: Copy files from remote to local
  fetch:
    src: /etc/pki/ca.pem
    dest: /etc/workloadmgr
    flat: yes

关于ansible - 如何在ansible中使用fetch模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63415143/

相关文章:

list - 如何将列表与特定键/值作为主机变量进行组合/匹配

jinja2 - 如何在 ansible 中测试 jinja2 模板?

Python:打开函数无法打开带有追加的新文件

linux - 使用变量作为角色名称ansible

python - Ansible 使用解析字符串和循环更新 Dict Var

json - Ansible:循环文件以执行 POST 请求

Ansible - 替换文件中的行

linux - 迭代 Ansible 设置命令

vagrant - 带有 Ansible 的客户机上的别名

带有条件的 Ansible ad-hoc 命令