- name: integration/become/sudo_nonexistent.yml
  hosts: test-targets
  tasks:

    - name: Verify behaviour for non-existent accounts.
      shell: whoami
      become: true
      become_user: slartibartfast
      ignore_errors: true
      register: out
      when:
        - become_unpriv_available

    - name: Verify raw module output.
      assert:
        that:
          - out.failed
          # sudo-1.8.6p3-29.el6_10.3 on RHEL & CentOS 6.10 (final release)
          # removed user/group error messages, as defence against CVE-2019-14287.
          - >-
            (out.module_stderr | default(out.module_stdout, true) | default(out.msg, true)) is search('sudo: unknown user:? slartibartfast')
            or (ansible_facts.os_family == 'RedHat' and ansible_facts.distribution_version == '6.10')
        fail_msg: |
          out={{ out }}
      when:
        - become_unpriv_available
  tags:
    - sudo
    - sudo_nonexistent
