mito’s blog

IT技術メインの雑記。思い立ったが吉日。

[Ansible] Amazonlinux2023に最新バージョンのAnsibleをさらっと入れる

はじめに

Amazon Linux 2023 のデフォルトリポジトリでは、すでに EOL(End of Life)を迎えた Ansible しか提供されていません。
そのため、最新の Ansible を利用するには、Python のバージョンを上げたうえで pip を使ってインストールする必要があります。


コマンド

Pythonのバージョンを上げて、pipでAnsibleをインストールします。

$ sudo dnf install -y python3.12
$ python3.12 -m ensurepip --default-pip
$ python3.12 -m pip install --user ansible
$ 
$ python3.12 -m pip list
Package      Version
------------ -------
ansible      11.2.0
ansible-core 2.18.2


AmazonlinuxのリポジトリのAnsible

以下のように、Amazonlinuxのリポジトリでは、AnsibleはEOLを迎えたバージョンしか提供されていません。

$ dnf list available ansible
ansible.noarch            8.3.0-1.amzn2023.0.1                        amazonlinux     
ansible-core.x86_64       2.15.3-1.amzn2023.0.7                       amazonlinux


Ansible コミュニティ パッケージ リリース 状態 コアバージョンの依存関係
12.0.0 開発中 2.19
11.x の変更履歴 現在 2.18
10.x の変更履歴 10.7 以降の EOL 2.17
9.x の変更履歴 9.13 以降の EOL 2.16
8.x の変更履歴 EOL(メンテナンスなし) 2.15
7.x の変更履歴 EOL(メンテナンスなし) 2.14

参考: Releases and maintenance — Ansible Community Documentation


実行ログ

# Pythonのバージョンを上げます
$ python3 -V
Python 3.9.20
$ 
$ dnf list available | grep python3
Available Packages
python3.11.x86_64                    3.11.6-1.amzn2023.0.6                      amazonlinux
python3.12.x86_64                    3.12.8-1.amzn2023.0.1                      amazonlinux
$ 
$ sudo dnf install -y python3.12
Last metadata expiration check: 0:03:26 ago on Tue Feb 18 11:17:09 2025.
Dependencies resolved.
==========================================================================================
 Package                       Architecture        Version                              Repository                Size
==========================================================================================
Installing:
 python3.12                    x86_64              3.12.8-1.amzn2023.0.1                amazonlinux               28 k
Installing dependencies:
 mpdecimal                     x86_64              2.5.1-3.amzn2023.0.3                 amazonlinux              101 k
 python3.12-libs               x86_64              3.12.8-1.amzn2023.0.1                amazonlinux              9.2 M
 python3.12-pip-wheel          noarch              23.2.1-4.amzn2023.0.1                amazonlinux              1.5 M

Transaction Summary
==========================================================================================
Install  4 Packages

Total download size: 11 M
Installed size: 44 M
Downloading Packages:
(1/4): mpdecimal-2.5.1-3.amzn2023.0.3.x86_64.rpm                           1.6 MB/s | 101 kB     00:00    
(2/4): python3.12-3.12.8-1.amzn2023.0.1.x86_64.rpm                         418 kB/s |  28 kB     00:00    
(3/4): python3.12-pip-wheel-23.2.1-4.amzn2023.0.1.noarch.rpm                15 MB/s | 1.5 MB     00:00    
(4/4): python3.12-libs-3.12.8-1.amzn2023.0.1.x86_64.rpm                     26 MB/s | 9.2 MB     00:00    
-------------------------------------------------------------------------------------------
Total                       26 MB/s |  11 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                   1/1 
  Installing       : python3.12-pip-wheel-23.2.1-4.amzn2023.0.1.noarch                 1/4 
  Installing       : mpdecimal-2.5.1-3.amzn2023.0.3.x86_64                             2/4 
  Installing       : python3.12-3.12.8-1.amzn2023.0.1.x86_64                           3/4 
  Installing       : python3.12-libs-3.12.8-1.amzn2023.0.1.x86_64                      4/4 
  Running scriptlet: python3.12-libs-3.12.8-1.amzn2023.0.1.x86_64                      4/4 
  Verifying        : mpdecimal-2.5.1-3.amzn2023.0.3.x86_64                             1/4 
  Verifying        : python3.12-3.12.8-1.amzn2023.0.1.x86_64                           2/4 
  Verifying        : python3.12-libs-3.12.8-1.amzn2023.0.1.x86_64                      3/4 
  Verifying        : python3.12-pip-wheel-23.2.1-4.amzn2023.0.1.noarch                 4/4 
==========================================================================================
WARNING:
  A newer release of "Amazon Linux" is available.

  Available Versions:

  Version 2023.6.20250211:
    Run the following command to upgrade to 2023.6.20250211:

      dnf upgrade --releasever=2023.6.20250211

    Release notes:
     https://docs.aws.amazon.com/linux/al2023/release-notes/relnotes-2023.6.20250211.html

==========================================================================================

Installed:
  mpdecimal-2.5.1-3.amzn2023.0.3.x86_64    python3.12-3.12.8-1.amzn2023.0.1.x86_64    python3.12-libs-3.12.8-1.amzn2023.0.1.x86_64    python3.12-pip-wheel-23.2.1-4.amzn2023.0.1.noarch   

Complete!
$ 
$ python3.12 -V
Python 3.12.8
$ 
$
# pipが入っていないので、インストールします
$ python3.12 -m pip --version
/usr/bin/python3.12: No module named pip
$ 
# ensurepipについてhttps://docs.python.org/ja/3/library/ensurepip.html
$ python3.12 -m ensurepip --default-pip
Defaulting to user installation because normal site-packages is not writeable
Looking in links: /tmp/tmp9u1g670u
Processing /tmp/tmp9u1g670u/pip-23.2.1-py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-23.2.1
$ 
$ python3.12 -m pip --version
pip 23.2.1 from /home/ec2-user/.local/lib/python3.12/site-packages/pip (python 3.12)
$ 
$ 
# Ansibleをインストールします
$ python3.12 -m pip show ansible
Name: ansible
Version: 11.2.0
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: info@ansible.com
License: GPL-3.0-or-later
Location: /home/ec2-user/.local/lib/python3.12/site-packages
Requires: ansible-core
Required-by: 
$ 
$ python3.12 -m pip install --user ansible 
Collecting ansible
  Obtaining dependency information for ansible from https://files.pythonhosted.org/packages/1f/6f/31a75c2360d488dfd8f9f826817ae559e6081a9e9b8eaa6530bcdf8c7359/ansible-11.2.0-py3-none-any.whl.metadata
  Downloading ansible-11.2.0-py3-none-any.whl.metadata (8.0 kB)
Collecting ansible-core~=2.18.2 (from ansible)
  Obtaining dependency information for ansible-core~=2.18.2 from https://files.pythonhosted.org/packages/5e/9a/a7dc8c604243eebd17c8160d261572047234b07d739ce5afb45b8a7a26df/ansible_core-2.18.2-py3-none-any.whl.metadata
  Downloading ansible_core-2.18.2-py3-none-any.whl.metadata (7.7 kB)
(略)
Installing collected packages: resolvelib, PyYAML, pycparser, packaging, MarkupSafe, jinja2, cffi, cryptography, ansible-core, ansible
Successfully installed MarkupSafe-3.0.2 PyYAML-6.0.2 ansible-11.2.0 ansible-core-2.18.2 cffi-1.17.1 cryptography-44.0.1 jinja2-3.1.5 packaging-24.2 pycparser-2.22 resolvelib-1.0.1

[notice] A new release of pip is available: 23.2.1 -> 25.0.1
[notice] To update, run: pip install --upgrade pip
$ 
$ python3.12 -m pip list
Package      Version
------------ -------
ansible      11.2.0
ansible-core 2.18.2
cffi         1.17.1
cryptography 44.0.1
Jinja2       3.1.5
MarkupSafe   3.0.2
packaging    24.2
pip          23.2.1
pycparser    2.22
PyYAML       6.0.2
resolvelib   1.0.1

[notice] A new release of pip is available: 23.2.1 -> 25.0.1
[notice] To update, run: pip install --upgrade pip
$ 
$ 
# 動作を確認します
$ ansible localhost -m ping
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
$ 


その他のバージョン

$ python3.12 -m pip index versions ansible
WARNING: pip index is currently an experimental command. It may be removed/changed in a future release without prior warning.
ansible (11.2.0)
Available versions: 11.2.0, 11.1.0, 11.0.0, 10.7.0, 10.6.0, 10.5.0, 10.4.0, 10.3.0, 10.2.0, 10.1.0, 10.0.1, 9.13.0, 9.12.0, 
9.11.0, 9.10.0, 9.9.0, 9.8.0, 9.7.0, 9.6.1, 9.5.1, 9.4.0, 9.3.0, 9.2.0, 9.1.0, 9.0.1, 8.7.0, 8.6.1, 8.6.0, 8.5.0, 8.4.0, 
8.3.0, 8.2.0, 8.1.0, 8.0.0, 7.7.0, 7.6.0, 7.5.0, 7.4.0, 7.3.0, 7.2.0, 7.1.0, 7.0.0, 6.7.0, 6.6.0, 6.5.0, 6.4.0, 6.3.0, 6.2.0, 
(略)
  INSTALLED: 11.2.0
  LATEST:    11.2.0
$ 
$ 
$ python3.12 -m pip index versions ansible-core
WARNING: pip index is currently an experimental command. It may be removed/changed in a future release without prior warning.
ansible-core (2.18.2)
Available versions: 2.18.2, 2.18.1, 2.18.0, 2.17.8, 2.17.7, 2.17.6, 2.17.5, 2.17.4, 2.17.3, 2.17.2, 2.17.1, 2.17.0, 2.16.14, 
2.16.13, 2.16.12, 2.16.11, 2.16.10, 2.16.9, 2.16.8, 2.16.7, 2.16.6, 2.16.5, 2.16.4, 2.16.3, 2.16.2, 2.16.1, 2.16.0, 2.15.13, 
2.15.12, 2.15.11, 2.15.10, 2.15.9, 2.15.8, 2.15.7, 2.15.6, 2.15.5, 2.15.4, 2.15.3, 2.15.2, 2.15.1, 2.15.0, 2.14.18, 2.14.17, 
(略)
  INSTALLED: 2.18.2
  LATEST:    2.18.2
$