[Ansible FAQs] The following modules failed to execute: ansible.legacy.setup

The following modules failed to execute: ansible.legacy.setup

Ansible is a powerful tool for automation, but sometimes running it on older systems can present challenges. Recently, while working with servers running Ubuntu 18.04, I encountered issues with the ansible.legacy.setup module failing to execute. This was primarily due to the outdated Python versions on these servers, which are not supported by the latest versions of Ansible.

Ubuntu 18.04, being an older distribution, does not appear in the Ubuntu Python 3 packages page. The core of the problem lies in the compatibility between the Python versions on these older servers and the Ansible versions being deployed.

Understanding Ansible’s Python Support

Ansible’s compatibility with different Python versions has evolved over time. As of the latest updates, Ansible no longer supports Python 2.7 in its more recent releases. Here’s a brief overview of Ansible’s Python support based on its core versions:

Ansible Community Package Release Status Core version dependency
11.0.0 In development (unreleased) 2.18
10.x Current 2.17
9.x Minor/patch releases (EOL Nov 2024) 2.16
8.x Unmaintained (end of life) 2.15
7.x Unmaintained (end of life) 2.14
6.x Unmaintained (end of life) 2.13
5.x Unmaintained (end of life) 2.12
4.x Unmaintained (end of life) 2.11
3.x Unmaintained (end of life) 2.10
2.10 Unmaintained (end of life) 2.10

For detailed changelogs, you can refer to the Ansible Community Documentation.

Addressing Compatibility Issues

To address compatibility issues on Ubuntu 18.04 servers, you can install an older version of Ansible that still supports Python 2.7. As per the documentation, ansible-core version 2.16 and earlier include support for Python 2.7. The recommended approach is to use Ansible 9.7.0, which is compatible with these older Python versions.

Installing Ansible 9.7.0

To install Ansible 9.7.0, use the following pip command:

1
pip install ansible==9.7.0

This ensures that your Ansible setup is compatible with the Python version available on Ubuntu 18.04 servers, allowing you to execute playbooks and modules without encountering the ansible.legacy.setup module failure.

Conclusion

Running Ansible on older servers requires careful consideration of Python version compatibility. By aligning your Ansible version with the supported Python versions on your target nodes, you can avoid execution failures and maintain smooth automation workflows. Keeping track of Ansible’s release notes and compatibility tables will help you make informed decisions and ensure your automation infrastructure remains robust and efficient.