Ansible:使用 Ansible 使用 Diff 命令 [英] Ansible: Use of Diff command using Ansible
本文介绍了Ansible:使用 Ansible 使用 Diff 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试一项简单的任务,即找出两个文件之间的差异并将其存储在记事本中.我无法使用命令和 shell 来做到这一点.请建议我哪里出错了-
I am trying to one simple task which is find out the difference between the two files and store it in notepad. I am not able to do it with command as well as shell. Please suggest where i am going wrong-
---
- hosts: myserver
tasks:
- name: get the difference
command: diff hosts.new hosts.mod
register: diff
- debug: var=diff.cmd
错误 -
fatal: [zlp12037]: FAILED! => {"changed": true, "cmd": ["diff", "hosts.new", "hosts.mod"], "delta": "0:00:00.003102", "end": "2017-03-29 10:17:34.448063", "failed": true, "rc": 1, "start": "2017-03-29 10:17:34.444961", "stderr": "", "stdout":
推荐答案
我不太确定您的输入播放在您的格式下是什么样子.但以下应该是一个解决方案:
I'm not quite sure what your input play looks like with your formatting. But the following should be a solution:
- name: "Get difference from two files"
command: diff filea fileb
args:
chdir: "/home/user/"
failed_when: "diff.rc > 1"
register: diff
- name: debug output
debug: msg="{{ diff.stdout }}"
一些解释:
- 如果 diff 命令失败,返回码 > 1.我们通过failed_when"来评估它.
- 为了获得命令的输出,我们打印.stdout"元素.
- 为确保我们位于文件所在的文件夹中,我们使用chdir".
这篇关于Ansible:使用 Ansible 使用 Diff 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文