[Playbook] - CentOS - module FAILED "The following modules failed to execute: ansible.legacy.setup"

Bonjour,

Environnement:
3 Machines tournant sous Vagrant

  • Ubuntu (controlplane)

  • Ubuntu (node)

  • CentOS10 (node)

  • Exécution du playbook sur node Ubuntu = exécution correct pas d’erreur.

  • Exécution du playbook sur node centos = Retourne une erreur.

  • Exécution du playbook sur node Ubuntu et centos = retourne une erreur.
    Le playbook refuse de s’exécuter une le node CentOS!

PS: python est bien à jour sur le node CentOS
PS: même problématique avec environnement fedora.

  • my code Error!
    fatal: [172.16.154.143]: FAILED! => {“ansible_facts”: {}, “changed”: false, “failed_modules”: {“ansible.legacy.setup”: {“ansible_facts”: {“discovered_interpreter_python”: “/usr/bin/python”}, “deprecations”: [{“msg”: “Distribution centos 10 on host 172.16.154.143 should use /usr/libexec/platform-python, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See Interpreter Discovery — Ansible Documentation for more information”, “version”: “2.12”}], “exception”: “Traceback (most recent call last):\r\n File "/home/vagrant/.ansible/tmp/ansible-tmp-1758378931.3669925-8418-85586770537722/AnsiballZ_setup.py", line 102, in \r\n _ansiballz_main()\r\n File "/home/vagrant/.ansible/tmp/ansible-tmp-1758378931.3669925-8418-85586770537722/AnsiballZ_setup.py", line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File "/home/vagrant/.ansible/tmp/ansible-tmp-1758378931.3669925-8418-85586770537722/AnsiballZ_setup.py", line 37, in invoke_module\r\n from ansible.module_utils import basic\r\n File "/tmp/ansible_ansible.legacy.setup_payload_fzdo9s94/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py", line 176, in \r\nModuleNotFoundError: No module named ‘ansible.module_utils.six.moves’\r\n”, “failed”: true, “module_stderr”: “Shared connection to 172.16.154.143 closed.\r\n”, “module_stdout”: “Traceback (most recent call last):\r\n File "/home/vagrant/.ansible/tmp/ansible-tmp-1758378931.3669925-8418-85586770537722/AnsiballZ_setup.py", line 102, in \r\n _ansiballz_main()\r\n File "/home/vagrant/.ansible/tmp/ansible-tmp-1758378931.3669925-8418-85586770537722/AnsiballZ_setup.py", line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File "/home/vagrant/.ansible/tmp/ansible-tmp-1758378931.3669925-8418-85586770537722/AnsiballZ_setup.py", line 37, in invoke_module\r\n from ansible.module_utils import basic\r\n File "/tmp/ansible_ansible.legacy.setup_payload_fzdo9s94/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py", line 176, in \r\nModuleNotFoundError: No module named ‘ansible.module_utils.six.moves’\r\n”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}}, “msg”: “The following modules failed to execute: ansible.legacy.setup\n”}

  • Set at least one tag (the experts follow the tags, so the right people will find you if you tag)

  • PLaybook d’install apache (basique)


  • hosts: all
    become: true
    tasks:
    • name: update repository index
      ansible.builtin.apt:
      update_cache: yes
      when: ansible_distribution == “Ubuntu”

    • name: install apache2 package
      ansible.builtin.apt:
      name: apache2
      state: latest
      when: ansible_distribution == “Ubuntu”

    • name: install support for php
      ansible.builtin.apt:
      name: libapache2-mod-php
      state: latest
      when: ansible_distribution == “Ubuntu”

    • name: update repository index
      ansible.builtin.yum:
      update_cache: yes
      when: ansible_distribution == “CentOS”

    • name: install httpd package
      ansible.builtin.yum:
      name: httpd
      state: latest
      when: ansible_distribution == “CentOS”

    • name: add php support for apache
      ansible.builtin.yum:
      name: php
      state: latest
      when: ansible_distribution == “CentOS”

Gros blocage sur ce probléme depuis deux jour, donc, par avance merci pour votre contribution et aide.

What version of Ansible are you using, and what version of python is /usr/bin/python on the centos node?

vagrant@controlplane:~/ansible_course$ ansible --version
ansible 2.10.8
config file = /home/vagrant/ansible_course/ansible.cfg
configured module search path = [‘/home/vagrant/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.10.12 (main, Aug 15 2025, 14:32:43) [GCC 11.4.0]
vagrant@controlplane:~/ansible_course$

[vagrant@node06 ~]$ python3 --version
Python 3.12.11
[vagrant@node06 ~]$ python3 -VV
Python 3.12.11 (main, Aug 14 2025, 00:00:00) [GCC 14.3.1 20250617 (Red Hat 14.3.1-2)]
[vagrant@node06 ~]$
[vagrant@node06 ~]$ whereis python
python: /usr/bin/python /usr/share/man/man1/python.1.gz
[vagrant@node06 ~]$

Two issues:

  1. Your ansible version is really old. I think 2.17 is the oldest, supported version right now. Did you install by package manager? If so, I would uninstall that and use pip to install it

  2. You listed the wrong python version. Do /usr/bin/python --version or python --version. python3 is a completely different install and one that ansible is not using

  1. Yes, ansible was installed by package manager
    Moreover i just try a apt command
    vagrant@controlplane:~/ansible_course$ sudo apt install ansible
    Reading package lists… Done
    Building dependency tree… Done
    Reading state information… Done
    ansible is already the newest version (2.10.7+merged+base+2.10.8+dfsg-1).
    0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
    vagrant@controlplane:~/ansible_course$

  2. [vagrant@node06 ~]$ /usr/bin/python --version
    Python 3.12.11
    [vagrant@node06 ~]$ python --version
    Python 3.12.11

Thanks Sir.

hi,

install python3 and pip on Ubuntu:
sudo apt update
sudo apt install python3-pip

sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common

sudo add-apt-repository --yes --update ppa:ansible/ansible

#Install Ansible
sudo apt install ansible -y

# finx broken install
sudo apt --fix-broken install

#Validate Ansible:
ansible ---version 
ansible [core 2.17.14]

Everything is running fine now, i think, topic can be closed.
1 Like