首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ansible synchronize always sets changed

Ansible synchronize always sets changed
EN

Stack Overflow用户
提问于 2020-05-31 12:19:27
回答 2查看 647关注 0票数 1

我需要将dest文件夹的内容设置为与我的src文件夹相同。所以我使用的是同步模块:

代码语言:javascript
复制
- name: files for /lib/user/ based on the Runtime version
  synchronize:
    src: "/data/managedFiles/lib/{{ runtime.version }}/user/"
    dest: "{{ mule_directory }}{{ mule_runtime_name }}/lib/user/"
    delete: yes
  register: result

但这会将result中的"changed“设置为”true“,即使没有任何更改。我只需要将它设置为'true‘,如果有什么改变,因为下一个任务测试此状态。

如果我在此任务之后立即重复相同的同步任务,则不会将“changed”设置为“true”。但它总是不会设置为“true”。

在不更改src的情况下,游戏的后续运行("/data/managedFiles/lib/{{ runtime.version }}/user/")总是将结果设置为“changed”。

EN

回答 2

Stack Overflow用户

发布于 2020-05-31 14:09:04

默认情况下,文件的时间戳包含在检测何时复制文件的测试中。由于这些文件是从git中拉出的,因此每个播放上的时间戳都不同,从而产生错误信号。但当同一同步连续运行两次时就不会了。解决方案是将checksum参数设置为yes,这样就不会检查时间戳。但这还需要设置递归和存档参数:

代码语言:javascript
复制
- name: files for /lib/user/ based on the Runtime version
  synchronize:
    src: "/data/managedFiles/lib/{{ runtime.version }}/user/"
    dest: "{{ mule_directory }}{{ mule_runtime_name }}/lib/user/"
    recursive: yes
    archive: no
    checksum: yes
    delete: yes
  register: result
票数 1
EN

Stack Overflow用户

发布于 2020-05-31 12:38:58

你可以有一些像这样的前置条件:

代码语言:javascript
复制
- name: check dest directory exists 
  stat:
     path: {{ mule_directory }}{{ mule_runtime_name }}/lib/user/
  register: exist_dir


- name: files for /lib/user/ based on the Runtime version
  synchronize:
    src: "/data/managedFiles/lib/{{ runtime.version }}/user/"
    dest: "{{ mule_directory }}{{ mule_runtime_name }}/lib/user/"
    delete: yes
  when: not exist_dir.stat.exists
  register: result

代码语言:javascript
复制
- name: Check whether {{ runtime.version }} exists somewhere in one of the file
  command: grep -Fxq "{{ runtime.version }}"    "{{ mule_directory }}{{ mule_runtime_name }}/lib/user/"
  register: checkversion
  check_mode: no
  ignore_errors: yes
  changed_when: no

- name: files for /lib/user/ based on the Runtime version
  synchronize:
    src: "/data/managedFiles/lib/{{ runtime.version }}/user/"
    dest: "{{ mule_directory }}{{ mule_runtime_name }}/lib/user/"
    delete: yes
  when: checkversion.rc != 0
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62111512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档