我想使用 Ansible 在远程位置覆盖文件。无论 zip 文件中的内容是否更改,每次我运行 playbook 文件时都需要在目标服务器上覆盖。
下面是我的剧本
- hosts: localhost
tasks:
- name: Checking if File is exsists to copy to update servers.
stat:
path: "/var/lib/abc.zip"
get_checksum: False
get_md5: False
register: win_stat_result
- debug:
var: win_stat_result.stat.exists
- hosts: uploads
tasks:
- name: Getting VARs
debug:
var: hostvars['localhost']['win_stat_result']['stat'] ['exists']
- name: copy Files to Destination Servers
win_copy:
src: "/var/lib/abc.zip"
dest: E:\xyz\data\charts.zip
force: yes
when: hostvars['localhost']['win_stat_result']['stat']['exists']
Run Code Online (Sandbox Code Playgroud)
当我运行这个剧本时,它没有覆盖目标上的文件,因为文件已经存在。我用过,force=yes但没有用。
尝试Ansible 复制模块。
复制模块默认覆盖设置为 dest 参数的现有文件(即强制默认为 yes)。源文件可以来自您连接的远程服务器,也可以来自运行 playbook 的本地计算机。这是一个代码片段:
- name: Overwrite file if it exists, the remote server has the source file bc remote_src is set below
copy:
src: "/var/lib/abc.zip"
dest: E:\xyz\data\charts.zip
remote_src: yes
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18197 次 |
| 最近记录: |