With the release of Ansible 2.4, we now require that managed nodes have a Python version of at least 2.6. Most notable, this leaves RHEL 5 users asking how to manage RHEL 5 systems in the future - since it only provides Python 2.4.
Background
With the release of Ansible 2.4 in September 2017, we have moved to support Python 2.6 or higher on the managed nodes. This means previous support for Python-2.4 or Python-2.5 is no longer available:
Support for Python-2.4 and Python-2.5 on the managed system's side was dropped. If you need to manage a system that ships with Python-2.4 or Python-2.5, you'll need to install Python-2.6 or better on the managed system.
This was bound to happen at some point in time because Python 2.6 was released almost 10 years ago, and most systems in production these days are based upon 2.6 or newer version. Furthermore, Python 3 is getting more and more traction, and in the long term we need to be able to support it. However, as the official Python documentation shows, code that runs on both Python 2.x and Python 3.x requires at least Python 2.6:
If you are able to skip Python 2.5 and older, then the required changes to your code should continue to look and feel like idiomatic Python code.
Thus the Ansible project had to make the change.
As a result, older Linux and UNIX releases only providing Python 2.4 are now faced with a challenge: How do I automate the management of my older environments that only provide Python-2.4?
We know organizations want to run their business critical applications for as long as possible, and this means running on older versions of Linux. We have seen this with Red Hat Enterprise Linux (RHEL) 5 customers who opted for the extended life cycle support until 2020 once the version reaches its end of life. However, RHEL 5 ships with Python-2.4, and thus users will see an error message even with the simplest Ansible 2.4 module:
$ ansible rhel5.qxyz.de -m ping
rhel5.qxyz.de | FAILED! => {
"changed": false,
"module_stderr": "Shared connection to rhel5.qxyz.de closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n
File
\"/home/rwolters/.ansible/tmp/ansible-tmp-1517240216.46-158969762588665/ping.py\", line 133, in ?\r\n exitcode = invoke_module(module, zipped_mod, ANSIBALLZ_PARAMS)\r\n File \"/home/rwolters/.ansible/tmp/ansible-tmp-1517240216.46-158969762588665/ping.py\", line 38, in invoke_module\r\n (stdout, stderr) = p.communicate(json_params)\r\n File \"/usr/lib64/python2.4/subprocess.py\", line 1050, in communicate\r\n stdout, stderr = self._communicate_with_poll(input)\r\n File \"/usr/lib64/python2.4/subprocess.py\", line 1113, in _communicate_with_poll\r\n input_offset += os.write(fd, chunk)\r\nOSError: [Errno 32] Broken pipe\r\n",
"msg": "MODULE FAILURE",
"rc": 0
}
This post will show three different ways to solve these errors and ease the migration until your servers can be upgraded.
1. Use Ansible 2.3
It is perfectly fine to use an older Ansible version. Some features and modules might be missing, but if you have to manage older Linux distributions and cannot install a newer Python version, using a slightly older Ansible version is a way to go. All old releases can be found at release.ansible.com/ansible.
As long as you are able to make the downgrade, and are only running the outdated Ansible version for a limited time, it is probably the easiest way to still automate your RHEL 5 machines.
2. Upgrade to a newer Python version
If you cannot use Ansible 2.3 but need to use a newer Ansible version with Red Hat Enterprise Linux 5 - upgrade the Python version on the managed nodes! However, as shown in the example below, especially with Python an updated version is usually installed to an alternative path to not break system tools. And Ansible needs to know where this is.
For example, the EPEL project provides Python 2.6 packages for Red Hat Enterprise Linux in their archives and we will show how to install and use them as an example. Note though that Python 2.6 as well as the EPEL packages for Red Hat Enterprise Linux 5 both reached end of life already, so you are on your own when it comes to support.
To install the packages on a managed node, the appropriate key and EPEL release package need to be installed. Then the package python26 is available for installation.
$ wget
https://archives.fedoraproject.org/pub/archive/epel/5/x86_64/epel-release-5-4.noarch.rpm
$ wget
https://archives.fedoraproject.org/pub/archive/epel/RPM-GPG-KEY-EPEL-5
$ sudo rpm --import RPM-GPG-KEY-EPEL-5
$ sudo yum install epel-release-5-4.noarch.rpm
$ sudo yum install python26
The package does not overwrite the Python binary, but installs the binary at an alternative path, /usr/bin/python2.6. So we need to tell Ansible to look at a different place for the Python library, which can be done with the flag ansible_python_interpreter for example directly in the inventory:
[old]
rhel5.qxyz.de ansible_python_interpreter=/usr/bin/python2.6
That way, the commands work again:
$ ansible rhel5.qxyz.de -m ping
rhel5.qxyz.de | SUCCESS => {
"changed": false,
"ping": "pong"
}
3. Use the power of RAW
Last but not least, there is another way to deal with old Python 2.4-only systems - or systems with no Python it all. Due to the way Ansible is built, almost all modules (for Linux/Unix systems, anyway) require Python to run. However, there are two notable exceptions: the raw module, and the script module. They both only send basic commands via the SSH connection, without invoking the underlying module subsystem.
That way, at least basic actions can be performed and managed via Ansible on legacy systems. Additionally, you can use the template function on the local control machine to create scripts on the fly dynamically before you execute them on the spot:
---
- name: control remote legacy system
hosts: legacy
gather_facts: no
vars_files:
- script_vars.yml
tasks:
- name: create script on the fly to manage system
template:
src: manage_script.sh.j2
dest: "{{ playbook_dir }}/manage_script.sh”
delegate_to: localhost
- name: execute management script on target system
script:
manage_script.sh
- name: execute raw command to upgrade system
raw:
yum upgrade -y
become: yes
One thing to note here: since Python is not working on the target system, we cannot collect facts and thus we must work with gather_facts: no.
As you see, that way we can include legacy systems in the automation, despite the fact that we are limited to few modules to work with.
Conclusion
For many customers, they want to support their business critical applications for as long as possible, this often includes running it on an older version of Red Hat Enterprise Linux. “If it ain’t broke, don’t fix it,” is a common mantra within IT departments. But automating these older, traditional systems which do not provide standard libraries can be challenging. here are multiple ways to deal with that - deciding which way is best depends on the overall situation and possibilities of the automation setup. Until organizations are faced with the pressing business need to modernize these older systems, Ansible is there to help.
執筆者紹介
チャンネル別に見る
自動化
テクノロジー、チームおよび環境に関する IT 自動化の最新情報
AI (人工知能)
お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート
オープン・ハイブリッドクラウド
ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。
セキュリティ
環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報
エッジコンピューティング
エッジでの運用を単純化するプラットフォームのアップデート
インフラストラクチャ
世界有数のエンタープライズ向け Linux プラットフォームの最新情報
アプリケーション
アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細
オリジナル番組
エンタープライズ向けテクノロジーのメーカーやリーダーによるストーリー
製品
ツール
試用、購入、販売
コミュニケーション
Red Hat について
エンタープライズ・オープンソース・ソリューションのプロバイダーとして世界をリードする Red Hat は、Linux、クラウド、コンテナ、Kubernetes などのテクノロジーを提供しています。Red Hat は強化されたソリューションを提供し、コアデータセンターからネットワークエッジまで、企業が複数のプラットフォームおよび環境間で容易に運用できるようにしています。
言語を選択してください
Red Hat legal and privacy links
- Red Hat について
- 採用情報
- イベント
- 各国のオフィス
- Red Hat へのお問い合わせ
- Red Hat ブログ
- ダイバーシティ、エクイティ、およびインクルージョン
- Cool Stuff Store
- Red Hat Summit