簡體   English   中英

Ansible 錯誤:AttributeError:模塊“平台”沒有屬性“dist”

[英]Ansible error: AttributeError: module 'platform' has no attribute 'dist'

我想通過 ansible 劇本在遠程機器中添加組,但出現錯誤。

這是我的劇本代碼:

- 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 
}

我的 ansible 在 WSL 上運行:

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 以使用 python3 版本來解決它。 原始指南在這里

sudo apt remove ansible -y && pip3 install ansible --user應該可以解決您的問題。 (如果你使用 apt 安裝 ansible)

更新 ansible 對我有用這里是 MacOS Monterrey M1 Max 芯片版本:

brew install ansible
brew link --overwrite ansible

我發現的主要原因是它強制ansible使用python3

ansible --version
ansible [core 2.12.4]
  config file = None
  configured module search path = ['/Users/userhome/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/5.5.0/libexec/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/userhome/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.2 (main, Feb  2 2022, 06:19:27) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 3.1.1
  libyaml = True

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM