ansible-galaxy 初始化安装失败 - 无法从 API 服务器获取数据 - 需要一个类似字节的对象,而不是 'str'

ansible-galaxy failing for init install - Failed to get data from the API server - a bytes-like object is required, not 'str'

ansible: ansible-galaxy 2.2.0.0

python: Python 2.7.10

我尝试使用 ansible-galaxy 命令创建新的角色结构(init 命令),但失败并显示以下消息。因此,我在网上查看并尝试了 --offline 选项和结构创建部分。

到目前为止,我有我的 Github 存储库:https://github.com/asangal/wavefront-ansible

角色在 Browse Roles 下的 Ansible Galaxy 中也可见。

https://galaxy.ansible.com/list#/roles?page=1&page_size=10&autocomplete=wavefront

https://galaxy.ansible.com/asangal/wavefront-ansible/

按照说明,我正在尝试 运行 安装步骤 运行ning 但它再次失败并显示相同的错误消息,如下所示。

$ ansible-galaxy install asangal.wavefront-ansible
 [WARNING]: - asangal.wavefront-ansible was NOT installed successfully: Failed to get data from the API server (https://galaxy.ansible.com/api/): a bytes-like object is
required, not 'str'

ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.

或(使用了 --ignore-errors-p <role_path> 选项,但没有帮助)

$ ansible-galaxy install asangal.wavefront-ansible --ignore-errors -p ~/aks/dummy
 [WARNING]: - asangal.wavefront-ansible was NOT installed successfully: Failed to get data from the API server (https://galaxy.ansible.com/api/): a bytes-like object is
required, not 'str'

[arun@vagrant ~/aks/dummy] $ ls -l
[arun@vagrant ~/aks/dummy] $

curl -v https://galaxy.ansible.com/asangal/wavefront-ansible/ 似乎工作正常。

为什么我会收到此错误:Failed to get data from the API server (https://galaxy.ansible.com/api/): a bytes-like object is required, not 'str'

我用 Python 2.7.13.

可以很好地下载你的角色

bytes-like object is required, not 'str' 与 Python3 相关,我想如果你使用 Python 2.x.

应该没问题

所以,感谢 Zlemini。所以澄清一下:

我的 ansible 实际上来自 Python 3.5 路径。即使默认 python 是 2.7.10.

[arun@host ~/aks/dummy] $ python --version
Python 2.7.10
[arun@host ~/aks/dummy] $ python3 --version
Python 3.5.2
[arun@host ~/aks/dummy] $ 

[arun@host ~/aks/dummy] $ which ansible-galaxy
/Library/Frameworks/Python.framework/Versions/3.5/bin/ansible-galaxy
[arun@host ~/aks/dummy] $ 

[arun@host ~/aks/dummy] $ which ansible
/Library/Frameworks/Python.framework/Versions/3.5/bin/ansible

运行 相同的 install 从我的另一台 vagrant 机器发出命令,其中 ansible 实际上来自 /usr/bin/ansible,该命令按预期工作。

$ ansible-galaxy install asangal.wavefront-ansible -p ~/aks/dummy
- downloading role 'wavefront-ansible', owned by asangal
- downloading role from https://github.com/asangal/wavefront-ansible/archive/master.tar.gz
- extracting asangal.wavefront-ansible to /home/vagrant/dummy/asangal.wavefront-ansible
- asangal.wavefront-ansible was installed successfully
[vagrant@myvagrant ~/aks/dummy] $ ls -l
total 4
drwxrwxr-x. 9 vagrant vagrant 4096 Jan 24 23:16 asangal.wavefront-ansible