I’m trying to execute ansible2 commnads…
When I do:
ansible-playbook -vvv -i my/inventory my/playbook.yml
Unexpected Exception: name ‘basestring’ is not defined
the full traceback was:
Traceback (most recent call last): File "/usr/local/bin/ansible-playbook", line 85, in <module> sys.exit(cli.run()) File "/usr/local/lib/python3.4/site-packages/ansible/cli/playbook.py", line 150, in run results = pbex.run() File "/usr/local/lib/python3.4/site-packages/ansible/executor/playbook_executor.py", line 87, in run self._tqm.load_callbacks() File "/usr/local/lib/python3.4/site-packages/ansible/executor/task_queue_manager.py", line 149, in load_callbacks elif isinstance(self._stdout_callback, basestring): NameError: name 'basestring' is not defined
ansible 188.8.131.52 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides
And here is
Ansible below version 2.5 requires Python 2.6 or 2.7 on the control host: Control Node Requirements
basestring is no longer available in Python 3. From What’s New In Python 3.0:
basestringabstract type was removed. Use
bytestypes don’t have functionality enough in common to warrant a shared base class. The
2to3tool (see below) replaces every occurrence of
So the solution is to either upgrade Ansible or downgrade Python.
basestring is not available in Python 3.:
This can be fixed for python 2.x and 3.x with the following:
try: basestring except NameError: basestring = str
I ran into this issue using Python 3 with Ansible and solved by forking the dopy project and installing dopy in my ansible script with:
If you are still getting errors be sure to change the
0.4.0 and remove any lingering dopy packages from your Python site-packages directory.
Also you could
pip3 install git+https://firstname.lastname@example.org#egg=dopy instead of in your Ansible Task.
Replace basestring with str. In 2.x basestring is there. but in 3.x the basestring has been replaced with “str”.
The problem might be due to python version. In 2.x, basestring is there but in 3.x it has been replaced with “str”.