【问题标题】:Ansible error: AttributeError: module 'platform' has no attribute 'dist'Ansible 错误:AttributeError:模块“平台”没有属性“dist”
【发布时间】:2020-06-17 13:35:38
【问题描述】:

我想通过 ansible playbook 在远程机器中添加组,但出现错误。

这是我在剧本中的代码:

- name: Ensure group for deploy_user exists
  become: yes
  group:
    name: "{{ deploy_user }}"
    state: present

这是我得到的错误:

fatal: [webserver]: FAILED! => {
"changed": false,
"module_stderr": "mux_client_request_session: read from master failed: Broken pipe\r\nShared connection to server closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_46blg1ge/ansible_modlib.zip/ansible/module_utils/basic.py\", line 274, in get_distribution\r\nAttributeError: module 'platform' has no attribute '_supported_dists'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_46blg1ge/ansible_module_group.py\", line 478, in <module>\r\n    main()\r\n  File \"/tmp/ansible_46blg1ge/ansible_module_group.py\", line 426, in main\r\n    group = Group(module)\r\n  File \"/tmp/ansible_46blg1ge/ansible_module_group.py\", line 80, in __new__\r\n    return load_platform_subclass(Group, args, kwargs)\r\n  File \"/tmp/ansible_46blg1ge/ansible_modlib.zip/ansible/module_utils/basic.py\", line 332, in load_platform_subclass\r\n  File \"/tmp/ansible_46blg1ge/ansible_modlib.zip/ansible/module_utils/basic.py\", line 284, in get_distribution\r\nAttributeError: module 'platform' has no attribute 'dist'\r\n",
"msg": "MODULE FAILURE",
"rc": 1 
}

我在 WSL 上运行的 ansible:

ansible 2.5.1
config file = /etc/ansible/ansible.cfg 
configured module search path = [u'/home/rideto/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] 
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Apr 15 2020, 17:20:14) [GCC 7.5.0]

请帮忙。

【问题讨论】:

  • 能否分享一下 ansible ping ad-hoc 命令的输出。您是否能够访问远程机器? ansible -i hosts_file host_group -m ping
  • 是的,我可以访问远程机器。以前的任务,如使用 apt 模块“升级所有包”或使用 npm 模块安装 yarn 可以正常运行。但是 ping 返回了该消息: webserver |失败的! => { "changed": false, "module_stderr": "mux_client_request_session: 从 master 读取失败:管道损坏\r\n与服务器的共享连接已关闭。\r\n", "module_stdout": "/bin/sh: 1: /usr/bin/python: 未找到\r\n", "msg": "MODULE FAILURE", "rc": 127 }
  • 好的。我必须在远程机器上安装 python。现在 ping 正常了。但问题依然存在。
  • 好的,您能否通过将-vvv 添加到ansible-playbok command 来分享输出。
  • 试试这个,如果它有效。 stackoverflow.com/a/51679353/10164003

标签: python deployment ansible


【解决方案1】:

我遇到了同样的问题,并通过重新安装 ansible 以使用 python3 版本解决了这个问题。 Original guide here.

sudo apt remove ansible -y &amp;&amp; pip3 install ansible --user 应该可以解决您的问题。 (如果你使用 apt 安装 ansible)

【讨论】:

  • 这打破了ansible:Command 'ansible' not found, but can be installed with: apt install ansible
猜你喜欢
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 2022-01-03
  • 2019-07-04
  • 2011-06-19
  • 2020-09-13
  • 1970-01-01
相关资源
最近更新 更多