# Ansible running command in two hosts and compare the outputs in one playbook

**URL:** <https://forum.ansible.com/t/ansible-running-command-in-two-hosts-and-compare-the-outputs-in-one-playbook/29558>\
**Category:** Ansible Project\
**Created:** [January 29, 2019, 7:50am UTC](https://forum.ansible.com/t/ansible-running-command-in-two-hosts-and-compare-the-outputs-in-one-playbook/29558 "2019-01-29T07:50:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansiblekrazy](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@ansiblekrazy](https://forum.ansible.com/u/ansiblekrazy)\
**Post date:** [January 29, 2019, 7:50am UTC](https://forum.ansible.com/t/ansible-running-command-in-two-hosts-and-compare-the-outputs-in-one-playbook/29558/1 "2019-01-29T07:50:00Z")

</div>

[Ask Question](https://stackoverflow.com/questions/ask)

-1

I’ve one playbook which runs on 2,3 hosts. I want to compare output of a command run on host 1 with output of command run on host 2

Something like below

```auto
- hosts: 1,2,3

  tasks:
   - name: Check file in tmp
     shell: ls -ltrh /tmp/a.txt
     register : tmp1
     when: "'1' in group_names"

   - name: Checking file in /tmp
     shell: ls -ltrh /tmp/b.txt
     when: "'2' in group_names" 
     register: tmp2

   - name: Checking file in /tmp
     command: /bin/true
     failed_when: tmp1 != tmp2

```

It is not evaluating the condition. Giving error :

fatal: [host2]: FAILED! =\> {“msg”: “The conditional check ‘tmp1 != tmp2’ failed. The error was: error while evaluating conditional ( tmp1 != tmp2): ‘dict object’ has no attribute ‘stdout’”}
