远程服务器上两个文件之间的比较

时间:2019-05-14 18:28:11

标签: ansible

是否可以使用ansible在两个远程服务器中比较文件。

Server A: /var/tmp/text1.txt
Server B: /var/tmp/text1.txt

我想检查两个文件的内容是否相同。

1 个答案:

答案 0 :(得分:4)

计算两个文件的校验和,然后比较校验和。假设我们的清单中有两个主机,分别为host1--- - hosts: all gather_facts: false tasks: - command: sha256sum /var/tmp/text1.txt register: cksum - hosts: localhost gather_facts: false tasks: - assert: that: hostvars.host0.cksum.stdout == hostvars.host1.cksum.stdout ,则可以这样进行:

// The generics interface:
public interface TypeConverter<S, R> {
    public R convert(S sourceType); 
}

// The implementation:
public DateConverter extends TypeConverter<String, Date> {
    public String convert(Date sourceType) { ... }
}

// Applying the custom converter through an annotation on a field:
...
Converter(DateConverter.class);
public Date dateField;
...

// The issue! Receiving the generic type in an annotation value:
public @interface Converter {
    //How to use the generic type as the type of "value"?
    Class value() default void.class;
    // versus
    //Class<? extends TypeConverter> type() default void.class;
}