how to search inside variables or debug ?

Ref: http://blog.toast38coza.me/custom-ansible-module-hello-world/

play.yml

  • hosts: test tasks:

  • name: Test that my module works
    logmonitor_v1:
    register: result

  • debug: var=result

  • name: Checking if there is any Error in log files
    fail: msg="{{ ansible_hostname }} , Error Found - "
    when: result == “1”

Python code


response = {"Error_Code": self.error_code}
module.exit_json(changed=False, meta=response)

When i run it : -


PLAY [test **************************************************************

TASK [setup] *******************************************************************
ok: [test]

TASK [Test that my module works] ***********************************************
ok: [test]

TASK [debug] *******************************************************************
ok: [test] => {
    "result": {
        "changed": false,
        "meta": {
            "Error_Code": "0"
        }
    }
}

TASK [Checking if there is any Error in log files] *****************************
skipping: [test]

PLAY RECAP *********************************************************************
test                : ok=3    changed=0    unreachable=0    failed=0



What i am trying do this : if Error_code Equal to 1, then give Fail message.
but it seems thsi Error_code is not storing into result .
Can you please help how can i do this ?

Thanks for the help.


As you can see, the Error_Code is under meta.

So your when need to be
  when: result.meta.Error_code == "1"

Perfect!!

Thanks for the quick help