Solaris11.4にPython3.9をインストールする

Ansible Collectionsのメンテナをやっていると、Solarisの面倒も見なければならないことがある。

現時点でのAnsibleのdevelブランチは、Python3.8以降のみをサポートしているが、どうもSolaris11では、公式に提供されているパッケージがないように見える。 そこで、しかたなくPython3.9をソースコードからビルドしてインストールしたので、その手順をメモしておく。もしかしたら、公式に提供されているパッケージが、この世にあるのかもしれない。

ちなみに、僕はSolarisが好きなので、自分がメンテナンスしているCollectionsでは、できる限りSolarisでも動作確認するようにしている。

環境

Python3.9のビルドとインストール

Linuxと違い、Solarisではビルドに必要なライブラリ群をあらかじめビルド&インストールしておく必要があることが多い。今回は、GNU grep最新のStable版(3.7)とlibffiの最新のStable版(3.7.4)のインストール程度で済んで幸運だった。

まずは、gccのインストールから。これは公式パッケージを利用するので、pkgコマンドでインストールする。

$ sudo pkg install gcc
$ gcc --version
gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

続いて、Python3.9.10のソースコードをダウンロードする。

$ mkdir work
$ cd work
~work$ wget https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz
~work$ tar zxvf Python-3.9.10.tgz
~work$ cd Python-3.9.10

configureの過程で、grepコマンドの結果からax_cv_c_float_words_bigendianをセットしているようだが、Solaris11.4のgrepは古すぎるらしく、Python3.9.10のconfigureで失敗する。

~/work/Python-3.9.10$ ./configure
...ship...
checking for --with-libm=STRING... default LIBM="-lm"
checking for --with-libc=STRING... default LIBC=""
checking for x64 gcc inline assembler... yes
checking whether float word ordering is bigendian... unknown
configure: error:

Unknown float word ordering. You need to manually preset
ax_cv_c_float_words_bigendian=no (or yes) according to your system.

この問題を回避するために、GNU grep 3.7をダウンロードしてインストールしてビルド&インストール(/usr/local/bin/配下)して利用する。

~/work$ wget https://ftp.gnu.org/gnu/grep/grep-3.7.tar.xz --no-check-certificat
~/work$ gtar Jxvf grep-3.7.tar.xz
~/work$ cd grep-3.7
~/work/grep-3.7$ ./configure
~/work/grep-3.7$ make
~/work/grep-3.7$ sudo make install
~/work$ wget https://ftp.gnu.org/gnu/grep/grep-3.7.tar.xz --no-check-certificat
~/work$ gtar Jxvf grep-3.7.tar.xz
~/work$ cd grep-3.7
~/work/grep-3.7$ ./configure
~/work/grep-3.7$ make
~/work/grep-3.7$ sudo make install

さらにPythonのビルドに必要となるilibffiもビルド&インストール。なにもかも皆懐かしい。

~/work$ wget https://github.com/libffi/libffi/releases/download/v3.4.2/libffi-3.4.2.tar.gz
~/work$ tar zxvf libffi-3.4.2.tar.gz
~/work/libffi-3.4.2$ ./configure
~/work/libffi-3.4.2$ make
~/work/libffi-3.4.2$ sudo make install

/usr/local/bin/に優先的にPATHを通してPython3.9.10をビルド&インストール。

~/work/Python-3.9.10$ ./configure
~/work/Python-3.9.10$ make
~/work/Python-3.9.10$ sudo make install
~/work/Python-3.9.10$ python3.9 --version
Python 3.9.10

ansible_python_interpreterの設定も忘れずに

Ansible Core(ansible-playbookなどのコマンドラインツール)の実行時には、inventoryのvarsとして ansible_python_interpreter を明示的に指定し、Interpreter Discoveryでの検知漏れを抑止しておくのも忘れずに。

[testserver]
solaris


[testserver:vars]
ansible_user=testuser
ansible_python_interpreter=/usr/local/bin/python3

#
# EOF
#