Ansible - 执行本地复制的最佳方式(在 pre_tasks 中)? [英] Ansible - Best way to perform a local copy (in pre_tasks)?

查看:25
本文介绍了Ansible - 执行本地复制的最佳方式(在 pre_tasks 中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剧本,需要将一些文件从本地目录复制到另一个本地目录(在 ansible 主机上).实现这一目标的正确方法是什么?

I have a playbook that requires to copy some files from a local directory into another local directory (on the ansible host). What is the correct way to achieve this?

我找到了 copy 模块 但它似乎仅用于将文件复制到远程主机.我还发现了 local_action 但我我非常不确定如何使用它.

I found the copy module but it seems it is only for copying files to a remote host. I also found local_action but I'am very unsure how to use it.

剧本看起来像:

---
- hosts: all
  vars:
    proprietary_files: "/some/files/not/managed/by/vcs"
    filesToWorkOnLater: "config_files"
  pre_tasks:
    - name "Copy from {{proprietary_files}} to {{filesToWorkOnLater}}"
   # What to enter here to perform the local copy?
   roles:
     ...   
...     

推荐答案

Ansible 现在支持 import_role 所以不再需要 pre_tasks.这样的事情应该可以解决您的问题:

Ansible now supports import_role so pre_tasks aren't needed anymore. Something like this should fix you issue:

- hosts: all
  tasks:
  - command: cp file1 file2
    delegate_to: 127.0.0.1
  - import_role:
      name: ...

这篇关于Ansible - 执行本地复制的最佳方式(在 pre_tasks 中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆