# Buggy code
def _edit_file_helper(
    self, filename, secret, existing_data=None, force_save=False, vault_id=None
):
    # Create a tempfile
    root, ext = os.path.splitext(os.path.realpath(filename))
    fd, tmp_path = tempfile.mkstemp(suffix=ext)
    os.close(fd)

    try:
        if existing_data:
            self.write_data(existing_data, tmp_path, shred=False)

        # drop the user into an editor on the tmp file
        subprocess.call(self._editor_shell_command(tmp_path))
    except:
        # whatever happens, destroy the decrypted file
        self._shred_file(tmp_path)
        raise

    b_tmpdata = self.read_data(tmp_path)

    # Do nothing if the content has not changed
    if existing_data == b_tmpdata and not force_save:
        self._shred_file(tmp_path)
        return

    # encrypt new data and write out to tmp
    # An existing vaultfile will always be UTF-8,
    # so decode to unicode here
    b_ciphertext = self.vault.encrypt(b_tmpdata, secret, vault_id=vault_id)
    self.write_data(b_ciphertext, tmp_path)

    # shuffle tmp file into place
    self.shuffle_files(tmp_path, filename)
    display.vvvvv(
        'Saved edited file "%s" encrypted using %s and  vault id "%s"'
        % (filename, secret, vault_id)
    )


# Traceback (OSError)
ansible-vault 2.6.3
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/the-noob/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-vault
python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
Using /etc/ansible/ansible.cfg as config file
Vault password:
ERROR! Unexpected Exception, this is probably a bug: [Errno 2] No such file or directory
the full traceback was:

Traceback (most recent call last):
File "/usr/bin/ansible-vault", line 118, in <module>
exit_code = cli.run()
File "/usr/lib/python2.7/dist-packages/ansible/cli/vault.py", line 255, in run
self.execute()
File "/usr/lib/python2.7/dist-packages/ansible/cli/__init__.py", line 155, in execute
fn()
File "/usr/lib/python2.7/dist-packages/ansible/cli/vault.py", line 446, in execute_edit
self.editor.edit_file(f)
File "/usr/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py", line 975, in edit_file
force_save=False, vault_id=vault_id)
File "/usr/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py", line 864, in _edit_file_helper
subprocess.call(self._editor_shell_command(tmp_path))
File "/usr/lib/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

# Fixed code
def _edit_file_helper(
    self, filename, secret, existing_data=None, force_save=False, vault_id=None
):
    # Create a tempfile
    root, ext = os.path.splitext(os.path.realpath(filename))
    fd, tmp_path = tempfile.mkstemp(suffix=ext)
    os.close(fd)

    cmd = self._editor_shell_command(tmp_path)
    try:
        if existing_data:
            self.write_data(existing_data, tmp_path, shred=False)

        # drop the user into an editor on the tmp file
        subprocess.call(cmd)
    except Exception as e:
        # whatever happens, destroy the decrypted file
        self._shred_file(tmp_path)
        raise AnsibleError(
            'Unable to execute the command "%s": %s' % (" ".join(cmd), to_native(e))
        )

    b_tmpdata = self.read_data(tmp_path)

    # Do nothing if the content has not changed
    if existing_data == b_tmpdata and not force_save:
        self._shred_file(tmp_path)
        return

    # encrypt new data and write out to tmp
    # An existing vaultfile will always be UTF-8,
    # so decode to unicode here
    b_ciphertext = self.vault.encrypt(b_tmpdata, secret, vault_id=vault_id)
    self.write_data(b_ciphertext, tmp_path)

    # shuffle tmp file into place
    self.shuffle_files(tmp_path, filename)
    display.vvvvv(
        'Saved edited file "%s" encrypted using %s and  vault id "%s"'
        % (filename, secret, vault_id)
    )