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

**URL:** <https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305>\
**Category:** Ansible Project\
**Created:** [January 21, 2016, 3:04pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305 "2016-01-21T15:04:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 3:04pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/1 "2016-01-21T15:04:17Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 21, 2016, 3:06pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/2 "2016-01-21T15:06:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 3:28pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/3 "2016-01-21T15:28:23Z")

</div>

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  
`

---

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 3:51pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/4 "2016-01-21T15:51:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 21, 2016, 3:51pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/5 "2016-01-21T15:51:40Z")

</div>

fixed via [http://github.com/ansible/ansible/commit/f26adcc7da7f8e6605167203249648f7b0e74fb7](http://github.com/ansible/ansible/commit/f26adcc7da7f8e6605167203249648f7b0e74fb7)

---

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 4:01pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/6 "2016-01-21T16:01:50Z")

</div>

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  
`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 21, 2016, 4:04pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/7 "2016-01-21T16:04:57Z")

</div>

are you trying to edit a non existant file?

---

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 4:09pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/8 "2016-01-21T16:09:17Z")

</div>

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) $  
`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 21, 2016, 4:40pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/9 "2016-01-21T16:40:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 4:48pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/10 "2016-01-21T16:48:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 21, 2016, 5:25pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/11 "2016-01-21T17:25:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 5:34pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/12 "2016-01-21T17:34:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 21, 2016, 5:40pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/13 "2016-01-21T17:40:28Z")

</div>

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](https://github.com/ansible/ansible/issues/14055)

---

<div class="post-metadata">

**Author:** ![Victor\_Keenan](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@Victor\_Keenan](https://forum.ansible.com/u/Victor_Keenan)\
**Post date:** [January 21, 2016, 5:45pm UTC](https://forum.ansible.com/t/ansible-vault-error-unexpected-exception-integer-division-or-modulo-by-zero/20305/14 "2016-01-21T17:45:56Z")

</div>

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