Ansible-Vault Error: Unexpected Exception: integer division or modulo by zero

When creating an Ansible vault with:

ansible-vault create test.yml

I receive the following error:

Unexpected Exception: integer division or modulo by zero

Does anyone have any tips on resolving this? Thanks for the help in advance!

what version are you using? there was a bug that caused this but it
has been fixed. Also output with -vvvv would be helfpul

Thanks Brian for the help! I’m using ansible 2.1.0 (devel 5e18bc5955). My -vvvv output is…

`
Unexpected Exception: integer division or modulo by zero
the full traceback was:

Traceback (most recent call last):
File “/Users/VictorSK/ansible/bin/ansible-vault”, line 85, in
sys.exit(cli.run())
File “/Users/VictorSK/ansible/lib/ansible/cli/vault.py”, line 119, in run
self.execute()
File “/Users/VictorSK/ansible/lib/ansible/cli/init.py”, line 99, in execute
fn()
File “/Users/VictorSK/ansible/lib/ansible/cli/vault.py”, line 151, in execute_create
self.editor.create_file(self.args[0])
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 341, in create_file
self._edit_file_helper(filename)
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 298, in _edit_file_helper
self._shred_file(tmp_path)
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 281, in _shred_file
self._shred_file_custom(tmp_path)
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 248, in _shred_file_custom
for _ in range(0, file_len // chunk_len):
ZeroDivisionError: integer division or modulo by zero
`

Also, I’m on Mac OS 10.11.3 running Python 2.7.10.

fixed via http://github.com/ansible/ansible/commit/f26adcc7da7f8e6605167203249648f7b0e74fb7

Thanks Brain! Progress, but now a different error…

`
ERROR! Unexpected Exception: [Errno 2] No such file or directory
the full traceback was:

Traceback (most recent call last):
File “/Users/VictorSK/ansible/bin/ansible-vault”, line 85, in
sys.exit(cli.run())
File “/Users/VictorSK/ansible/lib/ansible/cli/vault.py”, line 119, in run
self.execute()
File “/Users/VictorSK/ansible/lib/ansible/cli/init.py”, line 99, in execute
fn()
File “/Users/VictorSK/ansible/lib/ansible/cli/vault.py”, line 151, in execute_create
self.editor.create_file(self.args[0])
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 344, in create_file
self._edit_file_helper(filename)
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 298, in _edit_file_helper
call(self._editor_shell_command(tmp_path))
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 522, in call
return Popen(*popenargs, **kwargs).wait()
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 710, in init
errread, errwrite)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
`

are you trying to edit a non existant file?

No, I’m trying to create a new file/vault. Here is what I’m entering and the output…

`
local …pment/Ansible_Playbooks/server_lepr/vars(master) $ ls -an
total 0
drwxr-xr-x 2 501 20 68 Jan 21 11:07 .
drwxr-xr-x 9 501 20 306 Jan 21 10:56 …
local …pment/Ansible_Playbooks/server_lepr/vars(master) $ ansible-vault create victor.yml -vvvv
No config file found; using defaults
New Vault password:
Confirm New Vault password:
ERROR! Unexpected Exception: [Errno 2] No such file or directory
the full traceback was:

Traceback (most recent call last):
File “/Users/VictorSK/ansible/bin/ansible-vault”, line 85, in
sys.exit(cli.run())
File “/Users/VictorSK/ansible/lib/ansible/cli/vault.py”, line 119, in run
self.execute()
File “/Users/VictorSK/ansible/lib/ansible/cli/init.py”, line 99, in execute
fn()
File “/Users/VictorSK/ansible/lib/ansible/cli/vault.py”, line 151, in execute_create
self.editor.create_file(self.args[0])
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 344, in create_file
self._edit_file_helper(filename)
File “/Users/VictorSK/ansible/lib/ansible/parsing/vault/init.py”, line 298, in _edit_file_helper
call(self._editor_shell_command(tmp_path))
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 522, in call
return Popen(*popenargs, **kwargs).wait()
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 710, in init
errread, errwrite)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
local …pment/Ansible_Playbooks/server_lepr/vars(master) $
`

I cannot reproduce this ... but I'm on linux ...

It works on Ubuntu for me too. Just not on Mac OS X.

What contents are you putting in the vault file? I can get this to happen if I put nothing in the file. In which case the following is the cause:

File “/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/parsing/vault/init.py”, line 249, in _shred_file_custom
for _ in range(0, file_len // chunk_len):
ZeroDivisionError: integer division or modulo by zero

But is this happening if you put content into the file?

We should probably solve the above error regardless.

Also, what EDITOR is being used on Ubuntu and Mac? Are they both vim? What versions?

Hi Matt, thanks for the help!

I’m creating a blank file to add content. I thought the process was use

ansible-vault create filename.yml

and then it opens in your default editor to add content. Mine is Vim 7.3. I’m getting the error on create.

If I have an existing file with content already and use

ansible-vault encrypt filename.yml

it works fine. So does the decrypt command.

I think I understand the issue, and based on my experimentation I have created an issue which you can find at https://github.com/ansible/ansible/issues/14055

Thanks for the help Matt. I’ll follow the issue on Github.