Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ansible复制存在的特定文件_Ansible_Copy - Fatal编程技术网

使用Ansible复制存在的特定文件

使用Ansible复制存在的特定文件,ansible,copy,Ansible,Copy,我有一个角色,在大多数情况下我需要一个标准文件,但在某些主机上需要一个特定的文件。 在我角色的file文件夹中,我有file.default和file.{{ansible\u hostname}},用于特定情况 有没有一个很好的方法可以在一个任务中做到这一点? 或者我必须在三个时间内完成(如果特定文件存在,请统计,如果是,请复制,如果不是,请复制标准文件) 谢谢你找到了 这些文件之间的差异是否小到可以作为模板?如果是这样的话,您可以使用一个(或多个)变量,该变量的默认值为,对于hosts\u v

我有一个角色,在大多数情况下我需要一个标准文件,但在某些主机上需要一个特定的文件。 在我角色的
file
文件夹中,我有
file.default
file.{{ansible\u hostname}}
,用于特定情况

有没有一个很好的方法可以在一个任务中做到这一点? 或者我必须在三个时间内完成(如果特定文件存在,请统计,如果是,请复制,如果不是,请复制标准文件)

谢谢你找到了


这些文件之间的差异是否小到可以作为模板?如果是这样的话,您可以使用一个(或多个)变量,该变量的默认值为,对于
hosts\u vars
中的特定主机,该变量将被覆盖。
- name: |
        copy first existing file found to /some/file,
        looking in relative directories from where the task is defined and
        including any play objects that contain it
  copy: src={{lookup('first_found', findme)}} dest=/some/file
  vars:
    findme:
      - foo
      - "{{inventory_hostname}}"
      - bar