# Buggy code
def ask_vault_passwords(
    ask_vault_pass=False,
    ask_new_vault_pass=False,
    confirm_vault=False,
    confirm_new=False,
):
    """prompt for vault password and/or password change"""

    vault_pass = None
    new_vault_pass = None

    if ask_vault_pass:
        vault_pass = getpass.getpass(prompt="Vault password: ")

    if ask_vault_pass and confirm_vault:
        vault_pass2 = getpass.getpass(prompt="Confirm Vault password: ")
        if vault_pass != vault_pass2:
            raise errors.AnsibleError("Passwords do not match")

    if ask_new_vault_pass:
        new_vault_pass = getpass.getpass(prompt="New Vault password: ")

    if ask_new_vault_pass and confirm_new:
        new_vault_pass2 = getpass.getpass(prompt="Confirm New Vault password: ")
        if new_vault_pass != new_vault_pass2:
            raise errors.AnsibleError("Passwords do not match")

    # enforce no newline chars at the end of passwords
    if vault_pass:
        vault_pass = to_bytes(
            vault_pass, errors="strict", nonstring="simplerepr"
        ).strip()
    if new_vault_pass:
        new_vault_pass = to_bytes(
            new_vault_pass, errors="strict", nonstring="simplerepr"
        ).strip()

    return vault_pass, new_vault_pass


# Traceback (EOFError)
SUDO password: Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 324, in <module>
sys.exit(main(sys.argv[1:]))
File "/usr/bin/ansible-playbook", line 138, in main
become_method=prompt_method)
File "/usr/lib/python2.7/site-packages/ansible/utils/__init__.py", line 1134, in ask_passwords
becomepass = getpass.getpass(prompt=become_prompt)
File "/usr/lib/python2.7/getpass.py", line 71, in unix_getpass
passwd = _raw_input(prompt, stream, input=input)
File "/usr/lib/python2.7/getpass.py", line 135, in _raw_input
raise EOFError
EOFError

# Fixed code
def ask_vault_passwords(
    ask_vault_pass=False,
    ask_new_vault_pass=False,
    confirm_vault=False,
    confirm_new=False,
):
    """prompt for vault password and/or password change"""

    vault_pass = None
    new_vault_pass = None

    try:
        if ask_vault_pass:
            vault_pass = getpass.getpass(prompt="Vault password: ")

        if ask_vault_pass and confirm_vault:
            vault_pass2 = getpass.getpass(prompt="Confirm Vault password: ")
            if vault_pass != vault_pass2:
                raise errors.AnsibleError("Passwords do not match")

        if ask_new_vault_pass:
            new_vault_pass = getpass.getpass(prompt="New Vault password: ")

        if ask_new_vault_pass and confirm_new:
            new_vault_pass2 = getpass.getpass(prompt="Confirm New Vault password: ")
            if new_vault_pass != new_vault_pass2:
                raise errors.AnsibleError("Passwords do not match")
    except EOFError:
        pass

    # enforce no newline chars at the end of passwords
    if vault_pass:
        vault_pass = to_bytes(
            vault_pass, errors="strict", nonstring="simplerepr"
        ).strip()
    if new_vault_pass:
        new_vault_pass = to_bytes(
            new_vault_pass, errors="strict", nonstring="simplerepr"
        ).strip()

    return vault_pass, new_vault_pass