---

- hosts: localhost
  connection: local
  sudo: yes

  tasks:
    - name: Check node
      command: which node
      register: node_path

    - debug: 
        msg: "Node was installed in {{node_path.stdout}}"

    - fail: 
        msg: "Node Not Found, tests failed."
      when: node_path.stdout != "/usr/local/bin/node"

---

- hosts: localhost
  connection: local
  sudo: yes

  tasks:
    - name: Check node
      command: which node
      register: node_path

    - debug: 
        msg: "Node was installed in {{node_path.stdout}}"

    - fail: 
        msg: "Node Not Found, tests failed."
      when: node_path.rc != 0

Use return code to check that node was installed
Use return code to check that node was installed
