5

I want to add group in remote machine via ansible playbook and i get error.

This is my code from playbook:

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

and this is error what I get:

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 
}

My ansible running on 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]

Please help.

Bart
  • 53
  • 1
  • 1
  • 5
  • 1
    Could you please share the output of ansible ping ad-hoc command. Whether you are able to reach the remote machine or not? `ansible -i hosts_file host_group -m ping` – Shubham Vaishnav Jun 17 '20 at 15:23
  • Yes I am able to reach remote machine. Previous tasks like "Upgrade all packages" with apt module or install yarn with npm module run properly. But ping returned that message: 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": "/bin/sh: 1: /usr/bin/python: not found\r\n", "msg": "MODULE FAILURE", "rc": 127 } – Bart Jun 17 '20 at 17:10
  • Ok. I had to install python on remote machine. Now ping is ok. But problem still exists. – Bart Jun 17 '20 at 17:29
  • Okay, could you please share the output by adding `-vvv` to the `ansible-playbok command`. – Shubham Vaishnav Jun 17 '20 at 18:21
  • Try this, if it works. https://stackoverflow.com/a/51679353/10164003 – Shubham Vaishnav Jun 17 '20 at 18:22
  • https://gist.github.com/barnij/bf6b19fcb46832c5357461316412131c – Bart Jun 17 '20 at 19:02

2 Answers2

3

I faced the same issue and solved it by reinstalling ansible to use a python3 version. Original guide here.

sudo apt remove ansible -y && pip3 install ansible --user should solve your issue. (If you used apt to install ansible)

Milan Shah
  • 54
  • 3
  • This breaks ansible: `Command 'ansible' not found, but can be installed with: apt install ansible` – isaaclw Dec 08 '21 at 23:18
  • This work for me on MacOS Monterrey M1 Max chip: `brew link --overwrite ansible` and then `brew link --overwrite ansible`, you'll see `ansible --version` shows the path to python 3 – ddreliv Apr 06 '22 at 23:01
0

Updating ansible worked for me here's the MacOS Monterrey M1 Max chip version:

brew install ansible
brew link --overwrite ansible

The main reason I found was that it forced ansible to use 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
ddreliv
  • 181
  • 1
  • 11