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

Ask Question

-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

- 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’”}