--- - hosts: localhost tasks: - command: "grep {{ username }} /etc/passwd" register: result ignore_errors: True - debug: msg: '{{ username }} exists' when: result is success - debug: msg: '{{ username }} does not exist' when: result is failed