DEV Community

Philip LaVoie
Philip LaVoie

Posted on

Ansible Error: ImportError: No module named zipfile

Hello World,

This is probably more of a reminder to myself... however, If you happen to get this using Ansible 2.0, with Ubuntu 18.04.1 LTS, and a minimal current install of Python on your targets:

10.0.3.73 | FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 10.0.3.73 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1548966135.59-128122597125522/ping.py\", line 17, in <module>\r\n    import zipfile\r\nImportError: No module named zipfile\r\n",
    "msg": "MODULE FAILURE",
    "rc": 1
}
Enter fullscreen mode Exit fullscreen mode

It isn't you, it's them, and it's a terrible error.

I was running: ansible web -i inventory -m ping -u ubuntu -k

And my inventory file looked like:

[allservers]
10.0.3.202
10.0.3.19
10.0.3.73

[database]
10.0.3.202

[web]
10.0.3.19
10.0.3.73
Enter fullscreen mode Exit fullscreen mode

This is what i needed to do to 'fix' it... add bits like this to your inventory:

[allservers:vars]
ansible_python_interpreter=/usr/bin/python3

[database:vars]
ansible_python_interpreter=/usr/bin/python3

[web:vars]
ansible_python_interpreter=/usr/bin/python3
Enter fullscreen mode Exit fullscreen mode

Now your run should be a bit happier:

$ ansible allservers -i inventory -m ping -u ubuntu -k
SSH password:
10.0.3.73 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
10.0.3.19 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
10.0.3.202 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
Enter fullscreen mode Exit fullscreen mode

Happy Coding!

Top comments (1)

Collapse
 
kmoj86 profile image
kmoj86

THANK YOU!
I've been stuck for two days trying to figure this out