Unexpected Exception: name 'basestring' is not defined when invoking ansible2

后端 未结 5 717
逝去的感伤
逝去的感伤 2020-12-28 11:37

I\'m trying to execute ansible2 commnads...

When I do:

ansible-playbook -vvv -i my/inventory my/playbook.yml

I get:

相关标签:
5条回答
  • 2020-12-28 12:05

    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
    
    0 讨论(0)
  • 2020-12-28 12:08

    The problem might be due to python version. In 2.x, basestring is there but in 3.x it has been replaced with "str".

    0 讨论(0)
  • 2020-12-28 12:18

    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:

    The builtin basestring abstract type was removed. Use str instead. The str and bytes types don’t have functionality enough in common to warrant a shared base class. The 2to3 tool (see below) replaces every occurrence of basestring with str.

    So the solution is to either upgrade Ansible or downgrade Python.

    0 讨论(0)
  • 2020-12-28 12:26

    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:

    name: git+https://github.com/eodgooch/dopy@0.4.0#egg=dopy.

    If you are still getting errors be sure to change the version to 0.4.0 and remove any lingering dopy packages from your Python site-packages directory.

    Also you could pip3 install git+https://github.com/eodgooch/dopy@0.4.0#egg=dopy instead of in your Ansible Task.

    0 讨论(0)
  • 2020-12-28 12:27

    Replace basestring with str. In 2.x basestring is there. but in 3.x the basestring has been replaced with "str".

    0 讨论(0)
提交回复
热议问题