ansible diff忽略行的顺序

时间:2018-12-05 16:47:32

标签: ansible diff

直接从Ubuntu输入的diff命令提供了预期的输出,但是当它通过剧本输入时,会出现以下错误:

ubuntu@ubuntu:~$ diff <(sort CSR1_route.txt) <(sort CSR2_route.txt) >> delta1.txt ubuntu@ubuntu:~$ more delta1.txt 13c13 < O        2.2.2.2 [110/2] via 192.168.255.134, 01:36:31, GigabitEthernet1
---
> O        1.2.2.2 [110/2] via 192.168.255.134, 01:36:31, GigabitEthernet1


- name: testing_diff   shell: diff <(sort CSR1_route.txt) <(sort CSR2_route.txt) >> delta4.txt

fatal: [CSR1]: FAILED! => {
    "changed": true,
    "cmd": "diff <(sort CSR1_route.txt) <(sort CSR2_route.txt) >> delta4.txt",
    "delta": "0:00:00.001697",
    "end": "2018-12-05 16:34:59.665114",
    "invocation": {
        "module_args": {
            "_raw_params": "diff <(sort CSR1_route.txt) <(sort CSR2_route.txt) >> delta4.txt",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 2,
    "start": "2018-12-05 16:34:59.663417",
    "stderr": "/bin/sh: 1: Syntax error: \"(\" unexpected",
    "stderr_lines": [
        "/bin/sh: 1: Syntax error: \"(\" unexpected"
    ],
    "stdout": "",
    "stdout_lines": []

1 个答案:

答案 0 :(得分:0)

解决方案1-

- name: testing_diff   
  shell: |
    diff file1 file2 >> delta4.txt

解决方案2-

- name: testing_diff   
  shell: |
    diff file1 file2 >> delta4.txt
  args:
    executable: /bin/bash

解决方案3- 如果没有,请尝试使用命令模块。