Ansible 2.0 installation ERROR on ubuntu ! {Unexpected Exception: No module named markupsafe}

By | 4th May 2016

The latest Ansible is available now and it can be easily installed on
Ubuntu 14.
Ansible installation was giving the following error while trying to install.
It was pretty easy to get it fixed.

During the installation of Ansible it was giving the below error.

>>
rsa@ubdesktop:~$ ansible
ERROR! Unexpected Exception: No module named markupsafe
the full traceback was:
>>

Did the following steps to get it working !!

1. Make sure all the necessary packages are installed such as “paramiko
PyYAML Jinja2 httplib2 six”
Since in my case most of the packages were installed wanted to make
sure that they are of the latest versions used
upgrade.

2. Install the markupspace using pip

3. Install or Upgrade the Ansible using pip to get the error resolved.

>> Commands RAN –>
rsa@ubdesktop:~$ sudo pip install paramiko PyYAML Jinja2 httplib2 six –upgrade
Requirement already up-to-date: paramiko in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: PyYAML in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: Jinja2 in /usr/local/lib/python2.7/dist-packages
Downloading/unpacking httplib2 from https://pypi.python.org/packages/b1/e8/a49f534214a5c850faaad1678bea812991559d53bea49ecc7321f38a5757/httplib2-0.9.2.zip#md5=404bac4a4e0d10b3ba498ce483c8c456
Downloading httplib2-0.9.2.zip (210kB): 210kB downloaded
Running setup.py (path:/tmp/pip_build_root/httplib2/setup.py) egg_info for package httplib2

Requirement already up-to-date: six in /usr/local/lib/python2.7/dist-packages/six-1.10.0-py2.7.egg
Installing collected packages: httplib2
Found existing installation: httplib2 0.8
Not uninstalling httplib2 at /usr/lib/python2.7/dist-packages, owned by OS
Running setup.py install for httplib2

Successfully installed httplib2
Cleaning up…
rsa@ubdesktop:~$ sudo pip install ansible
Requirement already satisfied (use –upgrade to upgrade): ansible in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use –upgrade to upgrade): paramiko in /usr/local/lib/python2.7/dist-packages (from ansible)
Requirement already satisfied (use –upgrade to upgrade): jinja2 in /usr/local/lib/python2.7/dist-packages (from ansible)
Requirement already satisfied (use –upgrade to upgrade): PyYAML in /usr/local/lib/python2.7/dist-packages (from ansible)
Requirement already satisfied (use –upgrade to upgrade): setuptools in /usr/lib/python2.7/dist-packages (from ansible)
Requirement already satisfied (use –upgrade to upgrade): pycrypto>=2.6 in /usr/lib/python2.7/dist-packages (from ansible)
Cleaning up…

rsa@ubdesktop:~$ ansible
ERROR! Unexpected Exception: No module named markupsafe ———-> ERROR
the full traceback was:
Traceback (most recent call last):
File “/usr/local/bin/ansible”, line 75, in
from ansible.cli.adhoc import AdHocCLI as mycli
File “/usr/local/lib/python2.7/dist-packages/ansible/cli/adhoc.py”, line 28, in
from ansible.executor.task_queue_manager import TaskQueueManager
File “/usr/local/lib/python2.7/dist-packages/ansible/executor/task_queue_manager.py”, line 28, in
from ansible.executor.play_iterator import PlayIterator
File “/usr/local/lib/python2.7/dist-packages/ansible/executor/play_iterator.py”, line 29, in
from ansible.playbook.block import Block
File “/usr/local/lib/python2.7/dist-packages/ansible/playbook/__init__.py”, line 25, in
from ansible.playbook.play import Play
File “/usr/local/lib/python2.7/dist-packages/ansible/playbook/play.py”, line 27, in
from ansible.playbook.base import Base
File “/usr/local/lib/python2.7/dist-packages/ansible/playbook/base.py”, line 32, in
from jinja2.exceptions import UndefinedError
File “/usr/local/lib/python2.7/dist-packages/jinja2/__init__.py”, line 33, in
from jinja2.environment import Environment, Template
File “/usr/local/lib/python2.7/dist-packages/jinja2/environment.py”, line 13, in
from jinja2 import nodes
File “/usr/local/lib/python2.7/dist-packages/jinja2/nodes.py”, line 19, in
from jinja2.utils import Markup
File “/usr/local/lib/python2.7/dist-packages/jinja2/utils.py”, line 531, in <module>
from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe
r

>>

A simple pip install of markupsafe resolved the issue.

rsa@ubdesktop:~$ sudo pip install markupsafe
Downloading/unpacking markupsafe
Downloading MarkupSafe-0.23.tar.gz
Running setup.py (path:/tmp/pip_build_root/markupsafe/setup.py) egg_info for package markupsafe

Installing collected packages: markupsafe
Running setup.py install for markupsafe

building ‘markupsafe._speedups’ extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c markupsafe/_speedups.c -o build/temp.linux-x86_64-2.7/markupsafe/_speedups.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector –param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/markupsafe/_speedups.o -o build/lib.linux-x86_64-2.7/markupsafe/_speedups.so
Successfully installed markupsafe
Cleaning up…

Since Install did not give the expected results did an upgrade using the –upgrade option.

rsa@ubdesktop:~$ sudo pip install ansible –upgrade
Requirement already up-to-date: ansible in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: paramiko in /usr/local/lib/python2.7/dist-packages (from ansible)
Requirement already up-to-date: jinja2 in /usr/local/lib/python2.7/dist-packages (from ansible)
Requirement already up-to-date: PyYAML in /usr/local/lib/python2.7/dist-packages (from ansible)
Downloading/unpacking setuptools from https://pypi.python.org/packages/15/b7/a76624e5a3b18c8c1c8d33a5240b34cdabb08aef2da44b536a8b53ba1a45/setuptools-21.0.0-py2.py3-none-any.whl#md5=6027400d6870a7dad29952b7d2dfdc7b (from ansible)
Downloading setuptools-21.0.0-py2.py3-none-any.whl (509kB): 509kB downloaded
Requirement already up-to-date: pycrypto>=2.6 in /usr/lib/python2.7/dist-packages (from ansible)
Installing collected packages: setuptools
Found existing installation: setuptools 3.3
Not uninstalling setuptools at /usr/lib/python2.7/dist-packages, owned by OS
Successfully installed setuptools
Cleaning up…

Ansible 2.0.2 is up and working !!

rsa@ubdesktop:~$ ansible
Usage: ansible <host-pattern> [options]

Options:
-a MODULE_ARGS, –args=MODULE_ARGS
module arguments
–ask-become-pass     ask for privilege escalation password
-k, –ask-pass        ask for connection password
–ask-su-pass         ask for su password (deprecated, use become)
-K, –ask-sudo-pass   ask for sudo password (deprecated, use become)
–ask-vault-pass      ask for vault password
-B SECONDS, –background=SECONDS
run asynchronously, failing after X seconds
(default=N/A)
ERROR! Missing target hosts
rsa@ubdesktop:~$
====================================
rsa@ubdesktop:~$ ansible –version
ansible 2.0.2.0

=========================================